#include <Utils_ExceptHandlers.hxx>
#include "GEOM_Function.hxx"
+#include "GEOM_ISubShape.hxx"
#include "GEOM_PythonDump.hxx"
#include "Xao.hxx"
#include <TopAbs.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
+#include <TopTools_Array1OfShape.hxx>
+#include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
+#include <TopTools_MapOfShape.hxx>
+#include <TopTools_MapOfOrientedShape.hxx>
#include <TCollection_AsciiString.hxx>
#include <TColStd_HSequenceOfTransient.hxx>
return TopAbs_COMPOUND;
}
+XAO::Dimension shapeEnumToDimension(const TopAbs_ShapeEnum& shape)
+{
+ if (shape == TopAbs_VERTEX)
+ return XAO::VERTEX;
+ if (shape == TopAbs_EDGE)
+ return XAO::EDGE;
+ if (shape == TopAbs_FACE)
+ return XAO::FACE;
+ if (shape == TopAbs_SOLID)
+ return XAO::SOLID;
+ throw SALOME_Exception("Bad type"); // TODO
+}
+
//=============================================================================
/*!
* Export a shape to XAO format
{
Handle(GEOM_Object) currGroup = (*groupIterator++);
Handle(TColStd_HArray1OfInteger) groupIds = m_groupOperations->GetObjects(currGroup);
- XAO::Group* group = new XAO::Group();
- group->setName(currGroup->GetName());
+
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:
- group->setDimension(XAO::VERTEX);
for (int i = 1; i <= groupIds->Length(); i++)
{
- const char* ref = XAO::XaoUtils::intToString(groupIds->Value(i));
+ const char* ref = XAO::XaoUtils::intToString(groupIds->Value(i)).c_str();
const int index = geometry->getVertexIndexByReference(ref);
group->addElement(index);
}
break;
case TopAbs_EDGE:
- group->setDimension(XAO::EDGE);
for (int i = 1; i <= groupIds->Length(); i++)
{
- const char* ref = XAO::XaoUtils::intToString(groupIds->Value(i));
+ const char* ref = XAO::XaoUtils::intToString(groupIds->Value(i)).c_str();
const int index = geometry->getEdgeIndexByReference(ref);
group->addElement(index);
}
break;
case TopAbs_FACE:
- group->setDimension(XAO::FACE);
for (int i = 1; i <= groupIds->Length(); i++)
{
- const char* ref = XAO::XaoUtils::intToString(groupIds->Value(i));
+ const char* ref = XAO::XaoUtils::intToString(groupIds->Value(i)).c_str();
const int index = geometry->getFaceIndexByReference(ref);
group->addElement(index);
}
break;
case TopAbs_SOLID:
- group->setDimension(XAO::SOLID);
for (int i = 1; i <= groupIds->Length(); i++)
{
- const char* ref = XAO::XaoUtils::intToString(groupIds->Value(i));
+ const char* ref = XAO::XaoUtils::intToString(groupIds->Value(i)).c_str();
const int index = geometry->getSolidIndexByReference(ref);
group->addElement(index);
}
break;
}
-
- xaoObject->addGroup(group);
}
// TODO: add the fields
return true;
}
+bool GEOMImpl_IImportExportOperations::importSubShapes(XAO::Geometry* xaoGeometry,
+ Handle(GEOM_Function) function, Handle(TColStd_HSequenceOfTransient)& fieldList,
+ int shapeType, XAO::Dimension dim)
+{
+ Handle(GEOM_Object) subShape;
+ Handle(GEOM_Function) aFunction;
+ Handle(TColStd_HArray1OfInteger) anArray;
+ //for (int i = 0; i < xaoGeometry->countFaces(); i++)
+ XAO::GeometricElementList::iterator elementIterator = xaoGeometry->begin(dim);
+ for (; elementIterator != xaoGeometry->end(dim); elementIterator++)
+ {
+// if (!xaoGeometry->hasFaceName(i))
+// continue;
+ XAO::GeometricElement element = elementIterator->second;
+ if (!element.hasName())
+ continue;
+
+ //const char* name = xaoGeometry->getFaceName(i);
+ //const char* ref = xaoGeometry->getFaceReference(i);
+ std::string name = element.getName();
+ std::string ref = element.getReference();
+ int iref = atoi(ref.c_str());
+ //std::cout << "face: " << name << " ref = " << ref << std::endl;
+
+ //TopoDS_Shape aValue = facesByIndex[iref];
+ anArray = new TColStd_HArray1OfInteger(1, 1);
+ anArray->SetValue(1, iref);
+
+ subShape = GetEngine()->AddObject(GetDocID(), GEOM_SUBSHAPE);
+ Handle(GEOM_Function) aFunction = subShape->AddFunction(GEOM_Object::GetSubShapeID(), 1);
+ if (aFunction.IsNull())
+ return false;
+
+ subShape->SetName(name.c_str());
+ subShape->SetType(shapeType);
+
+ GEOM_ISubShape aSSI(aFunction);
+ aSSI.SetMainShape(function);
+ aSSI.SetIndices(anArray);
+
+// aFunction->SetValue(aValue);
+ fieldList->Append(subShape);
+
+ // Put this subshape in the list of sub-shapes of theMainShape
+ function->AddSubShapeReference(aFunction);
+ }
+
+ return true;
+}
+
//=============================================================================
/*!
* Import a shape from XAO format
// set the geometry
TopoDS_Shape geomShape = xaoGeometry->getShape();
function->SetValue(geomShape);
- shape->SetName(xaoGeometry->getName());
-
- // TODO: create sub shapes with names
+ shape->SetName(xaoGeometry->getName().c_str());
+
+ // create sub shapes with names
+
+ // get all the faces
+// TopTools_MapOfShape mapShape;
+// TopTools_ListOfShape listShape;
+// 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
int nbGroups = xaoObject->countGroups();
for (int j = 0; j < nbElt; j++)
{
int index = xaoGroup->getElement(j);
- const char* ref = xaoGeometry->getElementReference(xaoGroup->getDimension(), index);
- array->SetValue(j + 1, atoi(ref));
+ std::string ref = xaoGeometry->getElementReference(xaoGroup->getDimension(), index);
+ array->SetValue(j + 1, atoi(ref.c_str()));
}
// create the group with the array of sub shapes indexes
Handle(GEOM_Object) group = GetEngine()->AddSubShape(shape, array);
group->SetType(GEOM_GROUP);
- group->SetName(xaoGroup->getName());
+ group->SetName(xaoGroup->getName().c_str());
// Set a sub-shape type
TDF_Label freeLabel = group->GetFreeLabel();