mirror of
https://git.salome-platform.org/gitpub/modules/geom.git
synced 2025-02-05 14:14:17 +05:00
add list of sub shape to import
This commit is contained in:
parent
3861ed8a46
commit
a0d5e8f60e
@ -4018,9 +4018,8 @@ module GEOM
|
|||||||
* \param fields The list of fields to export
|
* \param fields The list of fields to export
|
||||||
* \param author The author of the export
|
* \param author The author of the export
|
||||||
* \param fileName The name of the file to export
|
* \param fileName The name of the file to export
|
||||||
* \return boolean indicating if export was succeful.
|
* \return boolean indicating if export was successful.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
boolean ExportXAO(in GEOM_Object shape,
|
boolean ExportXAO(in GEOM_Object shape,
|
||||||
in ListOfGO groups, in ListOfGO fields,
|
in ListOfGO groups, in ListOfGO fields,
|
||||||
in string author, in string fileName);
|
in string author, in string fileName);
|
||||||
@ -4029,13 +4028,13 @@ module GEOM
|
|||||||
* Import a shape from XAO format
|
* Import a shape from XAO format
|
||||||
* \param xao The name of the file to import
|
* \param xao The name of the file to import
|
||||||
* \param shape The imported shape
|
* \param shape The imported shape
|
||||||
|
* \param subShapes The list of imported subShapes
|
||||||
* \param groups The list of imported groups
|
* \param groups The list of imported groups
|
||||||
* \param fields The list of imported fields
|
* \param fields The list of imported fields
|
||||||
* \return boolean indicating if import was succeful.
|
* \return boolean indicating if import was successful.
|
||||||
*/
|
*/
|
||||||
|
boolean ImportXAO(in string fileName, out GEOM_Object shape,
|
||||||
boolean ImportXAO(in string fileName,
|
out ListOfGO subShapes, out ListOfGO groups, out ListOfGO fields);
|
||||||
out GEOM_Object shape, out ListOfGO groups, out ListOfGO fields);
|
|
||||||
|
|
||||||
/*@@ insert new functions before this line @@ do not remove this line @@*/
|
/*@@ insert new functions before this line @@ do not remove this line @@*/
|
||||||
};
|
};
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include <Standard_Stream.hxx>
|
#include <Standard_Stream.hxx>
|
||||||
|
#include <Utils_SALOME_Exception.hxx>
|
||||||
|
|
||||||
#include "GEOMImpl_Types.hxx"
|
#include "GEOMImpl_Types.hxx"
|
||||||
#include "GEOMImpl_IImportExportOperations.hxx"
|
#include "GEOMImpl_IImportExportOperations.hxx"
|
||||||
@ -142,6 +143,96 @@ XAO::Dimension shapeEnumToDimension(const TopAbs_ShapeEnum& shape)
|
|||||||
throw SALOME_Exception("Bad type"); // TODO
|
throw SALOME_Exception("Bad type"); // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GEOMImpl_IImportExportOperations::exportGroups(std::list<Handle(GEOM_Object)> groupList, XAO::Xao* xaoObject, XAO::BrepGeometry* geometry)
|
||||||
|
{
|
||||||
|
// add the groups
|
||||||
|
std::list<Handle(GEOM_Object)>::iterator groupIterator = groupList.begin();
|
||||||
|
while (groupIterator != groupList.end())
|
||||||
|
{
|
||||||
|
Handle(GEOM_Object) currGroup = (*groupIterator++);
|
||||||
|
Handle(TColStd_HArray1OfInteger) groupIds = m_groupOperations->GetObjects(currGroup);
|
||||||
|
|
||||||
|
TopAbs_ShapeEnum shapeGroup = m_groupOperations->GetType(currGroup);
|
||||||
|
XAO::Dimension dim = shapeEnumToDimension(shapeGroup);
|
||||||
|
XAO::Group* group = xaoObject->addGroup(currGroup->GetName(), dim);
|
||||||
|
|
||||||
|
switch (shapeGroup)
|
||||||
|
{
|
||||||
|
case TopAbs_VERTEX:
|
||||||
|
for (int i = 1; i <= groupIds->Length(); i++)
|
||||||
|
{
|
||||||
|
std::string ref = XAO::XaoUtils::intToString(groupIds->Value(i));
|
||||||
|
int index = geometry->getVertexIndexByReference(ref);
|
||||||
|
group->add(index);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TopAbs_EDGE:
|
||||||
|
for (int i = 1; i <= groupIds->Length(); i++)
|
||||||
|
{
|
||||||
|
std::string ref = XAO::XaoUtils::intToString(groupIds->Value(i));
|
||||||
|
int index = geometry->getEdgeIndexByReference(ref);
|
||||||
|
group->add(index);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TopAbs_FACE:
|
||||||
|
for (int i = 1; i <= groupIds->Length(); i++)
|
||||||
|
{
|
||||||
|
std::string ref = XAO::XaoUtils::intToString(groupIds->Value(i));
|
||||||
|
int index = geometry->getFaceIndexByReference(ref);
|
||||||
|
group->add(index);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TopAbs_SOLID:
|
||||||
|
for (int i = 1; i <= groupIds->Length(); i++)
|
||||||
|
{
|
||||||
|
std::string ref = XAO::XaoUtils::intToString(groupIds->Value(i));
|
||||||
|
int index = geometry->getSolidIndexByReference(ref);
|
||||||
|
group->add(index);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GEOMImpl_IImportExportOperations::exportFields(std::list<Handle(GEOM_Object)> fieldList, XAO::Xao* xaoObject, XAO::BrepGeometry* geometry)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
void GEOMImpl_IImportExportOperations::exportSubshapes(const Handle(GEOM_Object)& shape, XAO::BrepGeometry* geometry)
|
||||||
|
{
|
||||||
|
Handle(TColStd_HSequenceOfTransient) subObjects = m_shapesOperations->GetExistingSubObjects(shape, false);
|
||||||
|
int nbSubObjects = subObjects->Length();
|
||||||
|
// set the names of the sub shapes
|
||||||
|
for (int i = 1; i <= nbSubObjects; i++)
|
||||||
|
{
|
||||||
|
Handle(Standard_Transient) transientSubObject = subObjects->Value(i);
|
||||||
|
if (transientSubObject.IsNull())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Handle(GEOM_Object) subObject = Handle(GEOM_Object)::DownCast(transientSubObject);
|
||||||
|
if (subObject->GetType() != GEOM_GROUP)
|
||||||
|
{
|
||||||
|
int subIndex = m_shapesOperations->GetSubShapeIndex(shape, subObject);
|
||||||
|
switch (subObject->GetValue().ShapeType())
|
||||||
|
{
|
||||||
|
case TopAbs_VERTEX:
|
||||||
|
geometry->changeVertexName(subIndex, subObject->GetName());
|
||||||
|
break;
|
||||||
|
case TopAbs_EDGE:
|
||||||
|
geometry->changeEdgeName(subIndex, subObject->GetName());
|
||||||
|
break;
|
||||||
|
case TopAbs_FACE:
|
||||||
|
geometry->changeFaceName(subIndex, subObject->GetName());
|
||||||
|
break;
|
||||||
|
case TopAbs_SOLID:
|
||||||
|
geometry->changeSolidName(subIndex, subObject->GetName());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
/*!
|
/*!
|
||||||
* Export a shape to XAO format
|
* Export a shape to XAO format
|
||||||
@ -174,185 +265,89 @@ bool GEOMImpl_IImportExportOperations::ExportXAO(Handle(GEOM_Object) shape,
|
|||||||
if (exportFunction.IsNull()) return false;
|
if (exportFunction.IsNull()) return false;
|
||||||
if (exportFunction->GetDriverGUID() != GEOMImpl_XAODriver::GetID()) return false;
|
if (exportFunction->GetDriverGUID() != GEOMImpl_XAODriver::GetID()) return false;
|
||||||
|
|
||||||
// Build the XAO
|
// create the XAO object
|
||||||
XAO::Xao* xaoObject = new XAO::Xao();
|
XAO::Xao* xaoObject = new XAO::Xao();
|
||||||
xaoObject->setAuthor(author);
|
xaoObject->setAuthor(author);
|
||||||
|
|
||||||
XAO::Geometry* geometry = XAO::Geometry::createGeometry(XAO::BREP);
|
// add the geometry
|
||||||
|
XAO::BrepGeometry* geometry = (XAO::BrepGeometry*)XAO::Geometry::createGeometry(XAO::BREP);
|
||||||
|
TopoDS_Shape topoShape = shape->GetValue();
|
||||||
|
exportFunction->SetValue(topoShape);
|
||||||
|
XAO::BrepGeometry* brep = (XAO::BrepGeometry*)geometry;
|
||||||
|
brep->setTopoDS_Shape(topoShape);
|
||||||
|
|
||||||
geometry->setName(shape->GetName());
|
geometry->setName(shape->GetName());
|
||||||
|
exportSubshapes(shape, geometry);
|
||||||
if (geometry->getFormat() == XAO::BREP)
|
|
||||||
{
|
|
||||||
TopoDS_Shape topoShape = shape->GetValue();
|
|
||||||
exportFunction->SetValue(topoShape);
|
|
||||||
XAO::BrepGeometry* brep = (XAO::BrepGeometry*)geometry;
|
|
||||||
brep->setTopoDS_Shape(topoShape);
|
|
||||||
}
|
|
||||||
|
|
||||||
Handle(TColStd_HSequenceOfTransient) subObjects = m_shapesOperations->GetExistingSubObjects(shape, false);
|
|
||||||
int nbSubObjects = subObjects->Length();
|
|
||||||
|
|
||||||
// set the names of the sub shapes
|
|
||||||
int tmpIndex;
|
|
||||||
for (int i = 1; i <= nbSubObjects; i++)
|
|
||||||
{
|
|
||||||
Handle(Standard_Transient) transientSubObject = subObjects->Value(i);
|
|
||||||
if (transientSubObject.IsNull())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
Handle(GEOM_Object) subObject = Handle(GEOM_Object)::DownCast(transientSubObject);
|
|
||||||
if (subObject->GetType() != GEOM_GROUP)
|
|
||||||
{
|
|
||||||
int subIndex = m_shapesOperations->GetSubShapeIndex(shape, subObject);
|
|
||||||
// convert index to a string
|
|
||||||
std::stringstream str;
|
|
||||||
str << subIndex;
|
|
||||||
std::string strIndex = str.str();
|
|
||||||
|
|
||||||
switch (subObject->GetValue().ShapeType())
|
|
||||||
{
|
|
||||||
case TopAbs_VERTEX:
|
|
||||||
tmpIndex = geometry->getVertexIndexByReference(strIndex.c_str());
|
|
||||||
geometry->setVertexName(tmpIndex, subObject->GetName());
|
|
||||||
break;
|
|
||||||
case TopAbs_EDGE:
|
|
||||||
tmpIndex = geometry->getEdgeIndexByReference(strIndex.c_str());
|
|
||||||
geometry->setEdgeName(tmpIndex, subObject->GetName());
|
|
||||||
break;
|
|
||||||
case TopAbs_FACE:
|
|
||||||
tmpIndex = geometry->getFaceIndexByReference(strIndex.c_str());
|
|
||||||
geometry->setFaceName(tmpIndex, subObject->GetName());
|
|
||||||
break;
|
|
||||||
case TopAbs_SOLID:
|
|
||||||
tmpIndex = geometry->getSolidIndexByReference(strIndex.c_str());
|
|
||||||
geometry->setSolidName(tmpIndex, subObject->GetName());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
xaoObject->setGeometry(geometry);
|
xaoObject->setGeometry(geometry);
|
||||||
|
|
||||||
// add the groups
|
exportGroups(groupList, xaoObject, geometry);
|
||||||
std::list<Handle(GEOM_Object)>::iterator groupIterator = groupList.begin();
|
exportFields(fieldList, xaoObject, geometry);
|
||||||
while (groupIterator != groupList.end())
|
|
||||||
{
|
|
||||||
Handle(GEOM_Object) currGroup = (*groupIterator++);
|
|
||||||
Handle(TColStd_HArray1OfInteger) groupIds = m_groupOperations->GetObjects(currGroup);
|
|
||||||
|
|
||||||
|
|
||||||
TopAbs_ShapeEnum shapeGroup = m_groupOperations->GetType(currGroup);
|
|
||||||
XAO::Dimension dim = shapeEnumToDimension(shapeGroup);
|
|
||||||
XAO::Group* group = xaoObject->addGroup(currGroup->GetName(), dim);
|
|
||||||
|
|
||||||
switch (shapeGroup)
|
|
||||||
{
|
|
||||||
case TopAbs_VERTEX:
|
|
||||||
for (int i = 1; i <= groupIds->Length(); i++)
|
|
||||||
{
|
|
||||||
const char* ref = XAO::XaoUtils::intToString(groupIds->Value(i)).c_str();
|
|
||||||
const int index = geometry->getVertexIndexByReference(ref);
|
|
||||||
group->add(index);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case TopAbs_EDGE:
|
|
||||||
for (int i = 1; i <= groupIds->Length(); i++)
|
|
||||||
{
|
|
||||||
const char* ref = XAO::XaoUtils::intToString(groupIds->Value(i)).c_str();
|
|
||||||
const int index = geometry->getEdgeIndexByReference(ref);
|
|
||||||
group->add(index);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case TopAbs_FACE:
|
|
||||||
for (int i = 1; i <= groupIds->Length(); i++)
|
|
||||||
{
|
|
||||||
const char* ref = XAO::XaoUtils::intToString(groupIds->Value(i)).c_str();
|
|
||||||
const int index = geometry->getFaceIndexByReference(ref);
|
|
||||||
group->add(index);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case TopAbs_SOLID:
|
|
||||||
for (int i = 1; i <= groupIds->Length(); i++)
|
|
||||||
{
|
|
||||||
const char* ref = XAO::XaoUtils::intToString(groupIds->Value(i)).c_str();
|
|
||||||
const int index = geometry->getSolidIndexByReference(ref);
|
|
||||||
group->add(index);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: add the fields
|
|
||||||
|
|
||||||
// export the XAO to the file
|
// export the XAO to the file
|
||||||
xaoObject->exportXAO(fileName);
|
xaoObject->exportXAO(fileName);
|
||||||
delete xaoObject;
|
|
||||||
|
|
||||||
// make a Python command
|
// make a Python command
|
||||||
GEOM::TPythonDump pd(exportFunction);
|
GEOM::TPythonDump pd(exportFunction);
|
||||||
pd << "exported = geompy.ExportXAO(";
|
pd << "exported = geompy.ExportXAO(" << shape;
|
||||||
|
|
||||||
pd << shape;
|
// list of groups
|
||||||
pd << ", [";
|
pd << ", [";
|
||||||
|
|
||||||
if (groupList.size() > 0)
|
if (groupList.size() > 0)
|
||||||
{
|
{
|
||||||
std::list<Handle(GEOM_Object)>::iterator itG = groupList.begin();
|
std::list<Handle(GEOM_Object)>::iterator itGroup = groupList.begin();
|
||||||
pd << (*itG++);
|
pd << (*itGroup++);
|
||||||
while (itG != groupList.end())
|
while (itGroup != groupList.end())
|
||||||
{
|
{
|
||||||
pd << ", " << (*itG++);
|
pd << ", " << (*itGroup++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// list of fields
|
||||||
pd << "], [";
|
pd << "], [";
|
||||||
if (fieldList.size() > 0)
|
if (fieldList.size() > 0)
|
||||||
{
|
{
|
||||||
std::list<Handle(GEOM_Object)>::iterator itF = fieldList.begin();
|
std::list<Handle(GEOM_Object)>::iterator itField = fieldList.begin();
|
||||||
pd << (*itF++);
|
pd << (*itField++);
|
||||||
while (itF != fieldList.end())
|
while (itField != fieldList.end())
|
||||||
{
|
{
|
||||||
pd << ", " << (*itF++);
|
pd << ", " << (*itField++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pd << "], ";
|
pd << "], ";
|
||||||
pd << author << ", \"" << fileName << "\")";
|
pd << author << ", \"" << fileName << "\")";
|
||||||
|
|
||||||
SetErrorCode(OK);
|
SetErrorCode(OK);
|
||||||
|
delete xaoObject;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GEOMImpl_IImportExportOperations::importSubShapes(XAO::Geometry* xaoGeometry,
|
void GEOMImpl_IImportExportOperations::importSubShapes(XAO::Geometry* xaoGeometry,
|
||||||
Handle(GEOM_Function) function, Handle(TColStd_HSequenceOfTransient)& fieldList,
|
Handle(GEOM_Function) function, const int& shapeType, const XAO::Dimension& dim,
|
||||||
int shapeType, XAO::Dimension dim)
|
Handle(TColStd_HSequenceOfTransient)& subShapeList)
|
||||||
{
|
{
|
||||||
Handle(GEOM_Object) subShape;
|
Handle(GEOM_Object) subShape;
|
||||||
Handle(GEOM_Function) aFunction;
|
Handle(GEOM_Function) aFunction;
|
||||||
Handle(TColStd_HArray1OfInteger) anArray;
|
Handle(TColStd_HArray1OfInteger) anArray;
|
||||||
//for (int i = 0; i < xaoGeometry->countFaces(); i++)
|
|
||||||
XAO::GeometricElementList::iterator elementIterator = xaoGeometry->begin(dim);
|
XAO::GeometricElementList::iterator elementIterator = xaoGeometry->begin(dim);
|
||||||
for (; elementIterator != xaoGeometry->end(dim); elementIterator++)
|
for (; elementIterator != xaoGeometry->end(dim); elementIterator++)
|
||||||
{
|
{
|
||||||
// if (!xaoGeometry->hasFaceName(i))
|
|
||||||
// continue;
|
|
||||||
XAO::GeometricElement element = elementIterator->second;
|
XAO::GeometricElement element = elementIterator->second;
|
||||||
if (!element.hasName())
|
if (!element.hasName())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
//const char* name = xaoGeometry->getFaceName(i);
|
|
||||||
//const char* ref = xaoGeometry->getFaceReference(i);
|
|
||||||
std::string name = element.getName();
|
std::string name = element.getName();
|
||||||
std::string ref = element.getReference();
|
std::string ref = element.getReference();
|
||||||
int iref = atoi(ref.c_str());
|
int iref = XAO::XaoUtils::stringToInt(ref);
|
||||||
//std::cout << "face: " << name << " ref = " << ref << std::endl;
|
|
||||||
|
|
||||||
//TopoDS_Shape aValue = facesByIndex[iref];
|
|
||||||
anArray = new TColStd_HArray1OfInteger(1, 1);
|
anArray = new TColStd_HArray1OfInteger(1, 1);
|
||||||
anArray->SetValue(1, iref);
|
anArray->SetValue(1, iref);
|
||||||
|
|
||||||
subShape = GetEngine()->AddObject(GetDocID(), GEOM_SUBSHAPE);
|
subShape = GetEngine()->AddObject(GetDocID(), GEOM_SUBSHAPE);
|
||||||
Handle(GEOM_Function) aFunction = subShape->AddFunction(GEOM_Object::GetSubShapeID(), 1);
|
Handle(GEOM_Function) aFunction = subShape->AddFunction(GEOM_Object::GetSubShapeID(), 1);
|
||||||
if (aFunction.IsNull())
|
if (aFunction.IsNull())
|
||||||
return false;
|
return;
|
||||||
|
|
||||||
subShape->SetName(name.c_str());
|
subShape->SetName(name.c_str());
|
||||||
subShape->SetType(shapeType);
|
subShape->SetType(shapeType);
|
||||||
@ -361,14 +356,12 @@ bool GEOMImpl_IImportExportOperations::importSubShapes(XAO::Geometry* xaoGeometr
|
|||||||
aSSI.SetMainShape(function);
|
aSSI.SetMainShape(function);
|
||||||
aSSI.SetIndices(anArray);
|
aSSI.SetIndices(anArray);
|
||||||
|
|
||||||
// aFunction->SetValue(aValue);
|
//aFunction->SetValue(aValue);
|
||||||
fieldList->Append(subShape);
|
subShapeList->Append(subShape);
|
||||||
|
|
||||||
// Put this subshape in the list of sub-shapes of theMainShape
|
// Put this subshape in the list of sub-shapes of theMainShape
|
||||||
function->AddSubShapeReference(aFunction);
|
function->AddSubShapeReference(aFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
@ -376,6 +369,7 @@ bool GEOMImpl_IImportExportOperations::importSubShapes(XAO::Geometry* xaoGeometr
|
|||||||
* Import a shape from XAO format
|
* Import a shape from XAO format
|
||||||
* \param fileName The name of the file to import
|
* \param fileName The name of the file to import
|
||||||
* \param shape The imported shape
|
* \param shape The imported shape
|
||||||
|
* \param subShapes The list of imported groups
|
||||||
* \param groups The list of imported groups
|
* \param groups The list of imported groups
|
||||||
* \param fields The list of imported fields
|
* \param fields The list of imported fields
|
||||||
* \return boolean indicating if import was succeful.
|
* \return boolean indicating if import was succeful.
|
||||||
@ -383,21 +377,35 @@ bool GEOMImpl_IImportExportOperations::importSubShapes(XAO::Geometry* xaoGeometr
|
|||||||
//=============================================================================
|
//=============================================================================
|
||||||
bool GEOMImpl_IImportExportOperations::ImportXAO(const char* fileName,
|
bool GEOMImpl_IImportExportOperations::ImportXAO(const char* fileName,
|
||||||
Handle(GEOM_Object)& shape,
|
Handle(GEOM_Object)& shape,
|
||||||
Handle(TColStd_HSequenceOfTransient)& groupList,
|
Handle(TColStd_HSequenceOfTransient)& subShapes,
|
||||||
Handle(TColStd_HSequenceOfTransient)& fieldList)
|
Handle(TColStd_HSequenceOfTransient)& groups,
|
||||||
|
Handle(TColStd_HSequenceOfTransient)& fields)
|
||||||
{
|
{
|
||||||
SetErrorCode(KO);
|
SetErrorCode(KO);
|
||||||
|
|
||||||
if (fileName == NULL || groupList.IsNull() || fieldList.IsNull())
|
if (fileName == NULL || groups.IsNull() || fields.IsNull())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Read the XAO
|
// Read the XAO
|
||||||
XAO::Xao* xaoObject = new XAO::Xao();
|
XAO::Xao* xaoObject = new XAO::Xao();
|
||||||
xaoObject->importXAO(fileName);
|
try
|
||||||
|
{
|
||||||
|
xaoObject->importXAO(fileName);
|
||||||
|
}
|
||||||
|
catch (XAO::XAO_Exception& exc)
|
||||||
|
{
|
||||||
|
delete xaoObject;
|
||||||
|
SetErrorCode(exc.what());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
XAO::Geometry* xaoGeometry = xaoObject->getGeometry();
|
XAO::Geometry* xaoGeometry = xaoObject->getGeometry();
|
||||||
if (xaoGeometry == NULL)
|
if (xaoGeometry == NULL)
|
||||||
|
{
|
||||||
|
delete xaoObject;
|
||||||
|
SetErrorCode("Cannot import XAO: geometry format not supported.");
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// create the shape
|
// create the shape
|
||||||
shape = GetEngine()->AddObject(GetDocID(), GEOM_IMPORT);
|
shape = GetEngine()->AddObject(GetDocID(), GEOM_IMPORT);
|
||||||
@ -413,35 +421,18 @@ bool GEOMImpl_IImportExportOperations::ImportXAO(const char* fileName,
|
|||||||
function->SetValue(geomShape);
|
function->SetValue(geomShape);
|
||||||
shape->SetName(xaoGeometry->getName().c_str());
|
shape->SetName(xaoGeometry->getName().c_str());
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
delete xaoObject;
|
||||||
|
SetErrorCode("Cannot import XAO: geometry format not supported.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// create sub shapes with names
|
// create sub shapes with names
|
||||||
|
importSubShapes(xaoGeometry, function, GEOM_POINT, XAO::VERTEX, subShapes);
|
||||||
// get all the faces
|
importSubShapes(xaoGeometry, function, GEOM_EDGE, XAO::EDGE, subShapes);
|
||||||
// TopTools_MapOfShape mapShape;
|
importSubShapes(xaoGeometry, function, GEOM_FACE, XAO::FACE, subShapes);
|
||||||
// TopTools_ListOfShape listShape;
|
importSubShapes(xaoGeometry, function, GEOM_SOLID, XAO::SOLID, subShapes);
|
||||||
// TopExp_Explorer exp(geomShape, TopAbs_ShapeEnum(TopAbs_FACE));
|
|
||||||
// for (; exp.More(); exp.Next())
|
|
||||||
// {
|
|
||||||
// if (mapShape.Add(exp.Current()))
|
|
||||||
// listShape.Append(exp.Current());
|
|
||||||
// }
|
|
||||||
// TopTools_IndexedMapOfShape indices;
|
|
||||||
// TopExp::MapShapes(geomShape, indices);
|
|
||||||
|
|
||||||
// std::map<int, TopoDS_Shape> facesByIndex;
|
|
||||||
// TopTools_ListIteratorOfListOfShape itSub(listShape);
|
|
||||||
// for (int index = 1; itSub.More(); itSub.Next(), ++index)
|
|
||||||
// {
|
|
||||||
// TopoDS_Shape value = itSub.Value();
|
|
||||||
// facesByIndex[indices.FindIndex(value)] = value;
|
|
||||||
// }
|
|
||||||
|
|
||||||
std::cout << "==================" << std::endl;
|
|
||||||
importSubShapes(xaoGeometry, function, fieldList, GEOM_POINT, XAO::VERTEX);
|
|
||||||
importSubShapes(xaoGeometry, function, fieldList, GEOM_EDGE, XAO::EDGE);
|
|
||||||
importSubShapes(xaoGeometry, function, fieldList, GEOM_FACE, XAO::FACE);
|
|
||||||
importSubShapes(xaoGeometry, function, fieldList, GEOM_SOLID, XAO::SOLID);
|
|
||||||
std::cout << "==================" << std::endl;
|
|
||||||
|
|
||||||
// create groups
|
// create groups
|
||||||
int nbGroups = xaoObject->countGroups();
|
int nbGroups = xaoObject->countGroups();
|
||||||
@ -452,13 +443,12 @@ bool GEOMImpl_IImportExportOperations::ImportXAO(const char* fileName,
|
|||||||
// build an array with the indexes of the sub shapes
|
// build an array with the indexes of the sub shapes
|
||||||
int nbElt = xaoGroup->count();
|
int nbElt = xaoGroup->count();
|
||||||
Handle(TColStd_HArray1OfInteger) array = new TColStd_HArray1OfInteger(1, nbElt);
|
Handle(TColStd_HArray1OfInteger) array = new TColStd_HArray1OfInteger(1, nbElt);
|
||||||
//for (int j = 0; j < nbElt; j++)
|
|
||||||
int j = 0;
|
int j = 0;
|
||||||
for (std::set<int>::iterator it = xaoGroup->begin(); it != xaoGroup->end(); ++it)
|
for (std::set<int>::iterator it = xaoGroup->begin(); it != xaoGroup->end(); ++it)
|
||||||
{
|
{
|
||||||
int index = (*it);
|
int index = (*it);
|
||||||
std::string ref = xaoGeometry->getElementReference(xaoGroup->getDimension(), index);
|
std::string ref = xaoGeometry->getElementReference(xaoGroup->getDimension(), index);
|
||||||
array->SetValue(++j, atoi(ref.c_str()));
|
array->SetValue(++j, XAO::XaoUtils::stringToInt(ref));
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the group with the array of sub shapes indexes
|
// create the group with the array of sub shapes indexes
|
||||||
@ -469,7 +459,7 @@ bool GEOMImpl_IImportExportOperations::ImportXAO(const char* fileName,
|
|||||||
// Set a sub-shape type
|
// Set a sub-shape type
|
||||||
TDF_Label freeLabel = group->GetFreeLabel();
|
TDF_Label freeLabel = group->GetFreeLabel();
|
||||||
TDataStd_Integer::Set(freeLabel, (Standard_Integer) getGroupDimension(xaoGroup));
|
TDataStd_Integer::Set(freeLabel, (Standard_Integer) getGroupDimension(xaoGroup));
|
||||||
groupList->Append(group);
|
groups->Append(group);
|
||||||
|
|
||||||
function = group->GetLastFunction();
|
function = group->GetLastFunction();
|
||||||
}
|
}
|
||||||
@ -480,17 +470,34 @@ bool GEOMImpl_IImportExportOperations::ImportXAO(const char* fileName,
|
|||||||
GEOM::TPythonDump pd(function);
|
GEOM::TPythonDump pd(function);
|
||||||
pd << "(imported, " << shape << ", ";
|
pd << "(imported, " << shape << ", ";
|
||||||
|
|
||||||
|
// list of sub shapes
|
||||||
pd << "[";
|
pd << "[";
|
||||||
|
int nbSubshapes = subShapes->Length();
|
||||||
|
std::cout << "Nb SubShapes = " << nbSubshapes << std::endl;
|
||||||
|
if (nbSubshapes > 0)
|
||||||
|
{
|
||||||
|
for (int i = 1; i <= nbSubshapes; i++)
|
||||||
|
{
|
||||||
|
Handle(GEOM_Object) obj = Handle(GEOM_Object)::DownCast(subShapes->Value(i));
|
||||||
|
pd << obj << ((i < nbSubshapes) ? ", " : "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pd << "], [";
|
||||||
|
|
||||||
|
// list of groups
|
||||||
if (nbGroups > 0)
|
if (nbGroups > 0)
|
||||||
{
|
{
|
||||||
for (int i = 1; i <= nbGroups; i++)
|
for (int i = 1; i <= nbGroups; i++)
|
||||||
{
|
{
|
||||||
Handle(GEOM_Object) obj = Handle(GEOM_Object)::DownCast(groupList->Value(i));
|
Handle(GEOM_Object) obj = Handle(GEOM_Object)::DownCast(groups->Value(i));
|
||||||
pd << obj << ((i < nbGroups) ? ", " : "");
|
pd << obj << ((i < nbGroups) ? ", " : "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pd << "], []";
|
|
||||||
|
|
||||||
|
pd << "], [";
|
||||||
|
|
||||||
|
// list of fields
|
||||||
|
pd << "]";
|
||||||
pd << ") = geompy.ImportXAO(\"" << fileName << "\")";
|
pd << ") = geompy.ImportXAO(\"" << fileName << "\")";
|
||||||
|
|
||||||
delete xaoObject;
|
delete xaoObject;
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "GEOM_Object.hxx"
|
#include "GEOM_Object.hxx"
|
||||||
|
|
||||||
#include <XAO_Geometry.hxx>
|
#include <XAO_Geometry.hxx>
|
||||||
|
#include <XAO_BrepGeometry.hxx>
|
||||||
|
|
||||||
class GEOMImpl_IShapesOperations;
|
class GEOMImpl_IShapesOperations;
|
||||||
class GEOMImpl_IGroupOperations;
|
class GEOMImpl_IGroupOperations;
|
||||||
@ -44,17 +45,24 @@ public:
|
|||||||
const char* fileName);
|
const char* fileName);
|
||||||
Standard_EXPORT bool ImportXAO(const char* fileName,
|
Standard_EXPORT bool ImportXAO(const char* fileName,
|
||||||
Handle(GEOM_Object)& shape,
|
Handle(GEOM_Object)& shape,
|
||||||
Handle(TColStd_HSequenceOfTransient)& groupList,
|
Handle(TColStd_HSequenceOfTransient)& subShapes,
|
||||||
Handle(TColStd_HSequenceOfTransient)& fieldList);
|
Handle(TColStd_HSequenceOfTransient)& groups,
|
||||||
|
Handle(TColStd_HSequenceOfTransient)& fields);
|
||||||
/*@@ insert new functions before this line @@ do not remove this line @@*/
|
/*@@ insert new functions before this line @@ do not remove this line @@*/
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GEOMImpl_IShapesOperations* m_shapesOperations;
|
GEOMImpl_IShapesOperations* m_shapesOperations;
|
||||||
GEOMImpl_IGroupOperations* m_groupOperations;
|
GEOMImpl_IGroupOperations* m_groupOperations;
|
||||||
|
|
||||||
bool importSubShapes(XAO::Geometry* xaoGeometry,
|
void importSubShapes(XAO::Geometry* xaoGeometry, Handle(GEOM_Function) function,
|
||||||
Handle(GEOM_Function) function,
|
const int& shapeType, const XAO::Dimension& dim,
|
||||||
Handle(TColStd_HSequenceOfTransient)& fieldList, int shapeType, XAO::Dimension dim);
|
Handle(TColStd_HSequenceOfTransient)& subshapeList);
|
||||||
|
void exportSubshapes(const Handle(GEOM_Object)& shape, XAO::BrepGeometry* geometry);
|
||||||
|
void exportFields(std::list<Handle(GEOM_Object)> fieldList, XAO::Xao* xaoObject,
|
||||||
|
XAO::BrepGeometry* geometry);
|
||||||
|
void exportGroups(std::list<Handle(GEOM_Object)> groupList, XAO::Xao* xaoObject,
|
||||||
|
XAO::BrepGeometry* geometry);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -113,28 +113,39 @@ CORBA::Boolean GEOM_IImportExportOperations_i::ExportXAO(GEOM::GEOM_Object_ptr s
|
|||||||
//=============================================================================
|
//=============================================================================
|
||||||
CORBA::Boolean GEOM_IImportExportOperations_i::ImportXAO(const char* fileName,
|
CORBA::Boolean GEOM_IImportExportOperations_i::ImportXAO(const char* fileName,
|
||||||
GEOM::GEOM_Object_out shape,
|
GEOM::GEOM_Object_out shape,
|
||||||
|
GEOM::ListOfGO_out subShapes,
|
||||||
GEOM::ListOfGO_out groups,
|
GEOM::ListOfGO_out groups,
|
||||||
GEOM::ListOfGO_out fields)
|
GEOM::ListOfGO_out fields)
|
||||||
{
|
{
|
||||||
GEOM::GEOM_Object_var vshape;
|
GEOM::GEOM_Object_var vshape;
|
||||||
shape = vshape._retn();
|
shape = vshape._retn();
|
||||||
|
|
||||||
|
subShapes = new GEOM::ListOfGO;
|
||||||
groups = new GEOM::ListOfGO;
|
groups = new GEOM::ListOfGO;
|
||||||
fields = new GEOM::ListOfGO;
|
fields = new GEOM::ListOfGO;
|
||||||
|
|
||||||
// Set a not done flag
|
// Set a not done flag
|
||||||
GetOperations()->SetNotDone();
|
GetOperations()->SetNotDone();
|
||||||
|
|
||||||
|
Handle(TColStd_HSequenceOfTransient) importedSubShapes = new TColStd_HSequenceOfTransient();
|
||||||
Handle(TColStd_HSequenceOfTransient) importedGroups = new TColStd_HSequenceOfTransient();
|
Handle(TColStd_HSequenceOfTransient) importedGroups = new TColStd_HSequenceOfTransient();
|
||||||
Handle(TColStd_HSequenceOfTransient) importedFields = new TColStd_HSequenceOfTransient();
|
Handle(TColStd_HSequenceOfTransient) importedFields = new TColStd_HSequenceOfTransient();
|
||||||
Handle(GEOM_Object) hshape;
|
Handle(GEOM_Object) hshape;
|
||||||
bool res = GetOperations()->ImportXAO(fileName, hshape, importedGroups, importedFields);
|
bool res = GetOperations()->ImportXAO(fileName, hshape, importedSubShapes, importedGroups, importedFields);
|
||||||
|
|
||||||
if (!GetOperations()->IsDone() || !res)
|
if (!GetOperations()->IsDone() || !res)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// parse fields
|
||||||
|
int n = importedSubShapes->Length();
|
||||||
|
subShapes->length(n);
|
||||||
|
for (int i = 1; i <= n; i++)
|
||||||
|
{
|
||||||
|
(*subShapes)[i - 1] = GetObject(Handle(GEOM_Object)::DownCast(importedSubShapes->Value(i)));
|
||||||
|
}
|
||||||
|
|
||||||
// parse groups
|
// parse groups
|
||||||
int n = importedGroups->Length();
|
n = importedGroups->Length();
|
||||||
groups->length(n);
|
groups->length(n);
|
||||||
for (int i = 1; i <= n; i++)
|
for (int i = 1; i <= n; i++)
|
||||||
{
|
{
|
||||||
|
@ -45,6 +45,7 @@ public:
|
|||||||
const char* fileName);
|
const char* fileName);
|
||||||
CORBA::Boolean ImportXAO (const char* fileName,
|
CORBA::Boolean ImportXAO (const char* fileName,
|
||||||
GEOM::GEOM_Object_out shape,
|
GEOM::GEOM_Object_out shape,
|
||||||
|
GEOM::ListOfGO_out subShapes,
|
||||||
GEOM::ListOfGO_out groups,
|
GEOM::ListOfGO_out groups,
|
||||||
GEOM::ListOfGO_out fields);
|
GEOM::ListOfGO_out fields);
|
||||||
/*@@ insert new functions before this line @@ do not remove this line @@*/
|
/*@@ insert new functions before this line @@ do not remove this line @@*/
|
||||||
|
Loading…
Reference in New Issue
Block a user