From 56cbe2761516876153e830ece95bc2c02fa6b5e1 Mon Sep 17 00:00:00 2001 From: fps Date: Wed, 28 Aug 2013 15:55:00 +0000 Subject: [PATCH] fix change in XAO API --- .../GEOMImpl_IImportExportOperations.cxx | 128 +++++++++++++++--- .../GEOMImpl_IImportExportOperations.hxx | 19 ++- .../ImportExportGUI_ImportXAODlg.cxx | 17 ++- .../ImportExportGUI_ImportXAODlg.h | 1 + 4 files changed, 137 insertions(+), 28 deletions(-) diff --git a/src/GEOMImpl/GEOMImpl_IImportExportOperations.cxx b/src/GEOMImpl/GEOMImpl_IImportExportOperations.cxx index 51d08b449..03eb3003f 100644 --- a/src/GEOMImpl/GEOMImpl_IImportExportOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IImportExportOperations.cxx @@ -42,6 +42,7 @@ #include #include "GEOM_Function.hxx" +#include "GEOM_ISubShape.hxx" #include "GEOM_PythonDump.hxx" #include "Xao.hxx" @@ -61,6 +62,11 @@ #include #include +#include +#include +#include +#include +#include #include #include @@ -121,6 +127,19 @@ TopAbs_ShapeEnum getGroupDimension(XAO::Group* group) 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 @@ -212,51 +231,47 @@ bool GEOMImpl_IImportExportOperations::ExportXAO(Handle(GEOM_Object) shape, { 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 @@ -299,6 +314,56 @@ bool GEOMImpl_IImportExportOperations::ExportXAO(Handle(GEOM_Object) shape, 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 @@ -336,9 +401,36 @@ bool GEOMImpl_IImportExportOperations::ImportXAO(const char* fileName, // 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 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(); @@ -352,14 +444,14 @@ bool GEOMImpl_IImportExportOperations::ImportXAO(const char* fileName, 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(); diff --git a/src/GEOMImpl/GEOMImpl_IImportExportOperations.hxx b/src/GEOMImpl/GEOMImpl_IImportExportOperations.hxx index 4e7c42638..2a5511f86 100644 --- a/src/GEOMImpl/GEOMImpl_IImportExportOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_IImportExportOperations.hxx @@ -19,24 +19,20 @@ #ifndef _GEOMImpl_IImportExportOperations_HXX_ #define _GEOMImpl_IImportExportOperations_HXX_ +#include + #include #include "GEOM_IOperations.hxx" #include "GEOM_Engine.hxx" #include "GEOM_Object.hxx" -#include +#include "Geometry.hxx" class GEOMImpl_IShapesOperations; class GEOMImpl_IGroupOperations; class GEOMImpl_IImportExportOperations: public GEOM_IOperations { - -private: - - GEOMImpl_IShapesOperations* m_shapesOperations; - GEOMImpl_IGroupOperations* m_groupOperations; - public: Standard_EXPORT GEOMImpl_IImportExportOperations(GEOM_Engine* engine, int docID); Standard_EXPORT ~GEOMImpl_IImportExportOperations(); @@ -51,5 +47,14 @@ public: Handle(TColStd_HSequenceOfTransient)& groupList, Handle(TColStd_HSequenceOfTransient)& fieldList); /*@@ insert new functions before this line @@ do not remove this line @@*/ + +private: + GEOMImpl_IShapesOperations* m_shapesOperations; + GEOMImpl_IGroupOperations* m_groupOperations; + + bool importSubShapes(XAO::Geometry* xaoGeometry, + Handle(GEOM_Function) function, + Handle(TColStd_HSequenceOfTransient)& fieldList, int shapeType, XAO::Dimension dim); + }; #endif diff --git a/src/ImportExportGUI/ImportExportGUI_ImportXAODlg.cxx b/src/ImportExportGUI/ImportExportGUI_ImportXAODlg.cxx index fa6cd11eb..8fca1ad09 100644 --- a/src/ImportExportGUI/ImportExportGUI_ImportXAODlg.cxx +++ b/src/ImportExportGUI/ImportExportGUI_ImportXAODlg.cxx @@ -221,13 +221,22 @@ bool ImportExportGUI_ImportXAODlg::execute(ObjectList& objects) if (!shape->_is_nil()) { + m_mainShape = shape; objects.push_back(shape._retn()); } + else + { + m_mainShape = NULL; + } for (int i = 0; i < groups->length(); i++) { objects.push_back(GEOM::GEOM_Object::_duplicate(groups[i])); } + for (int i = 0; i < fields->length(); i++) + { + objects.push_back(GEOM::GEOM_Object::_duplicate(fields[i])); + } return res; } @@ -235,10 +244,11 @@ bool ImportExportGUI_ImportXAODlg::execute(ObjectList& objects) GEOM::GEOM_Object_ptr ImportExportGUI_ImportXAODlg::getFather(GEOM::GEOM_Object_ptr object) { GEOM::GEOM_Object_var fatherObj; - if (object->GetType() == GEOM_GROUP) + if (object->GetType() != GEOM_IMPORT && m_mainShape != NULL) { - GEOM::GEOM_IGroupOperations_var groupOper = getGeomEngine()->GetIGroupOperations(getStudyId()); - fatherObj = groupOper->GetMainShape(object); + //GEOM::GEOM_IGroupOperations_var groupOper = getGeomEngine()->GetIGroupOperations(getStudyId()); + //fatherObj = groupOper->GetMainShape(object); + fatherObj = m_mainShape; } return fatherObj._retn(); } @@ -249,3 +259,4 @@ QString ImportExportGUI_ImportXAODlg::getObjectName(GEOM::GEOM_Object_ptr object return QString::null; return object->GetName(); } + diff --git a/src/ImportExportGUI/ImportExportGUI_ImportXAODlg.h b/src/ImportExportGUI/ImportExportGUI_ImportXAODlg.h index 517d57624..085c7bd90 100644 --- a/src/ImportExportGUI/ImportExportGUI_ImportXAODlg.h +++ b/src/ImportExportGUI/ImportExportGUI_ImportXAODlg.h @@ -53,6 +53,7 @@ private: private: QLineEdit* ledFileName; QPushButton* btnFileSelect; + GEOM::GEOM_Object_var m_mainShape; private slots: void ClickOnOk(); -- 2.39.2