]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
fix change in XAO API
authorfps <fps@opencascade.com>
Wed, 28 Aug 2013 15:55:00 +0000 (15:55 +0000)
committerfps <fps@opencascade.com>
Wed, 28 Aug 2013 15:55:00 +0000 (15:55 +0000)
src/GEOMImpl/GEOMImpl_IImportExportOperations.cxx
src/GEOMImpl/GEOMImpl_IImportExportOperations.hxx
src/ImportExportGUI/ImportExportGUI_ImportXAODlg.cxx
src/ImportExportGUI/ImportExportGUI_ImportXAODlg.h

index 51d08b449767f8f1f09ec5987bec5bdf2ef7081f..03eb3003fae6762f66a6b3c705ee3572c845d98b 100644 (file)
@@ -42,6 +42,7 @@
 #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>
@@ -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<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();
@@ -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();
index 4e7c42638ea375c9dc796838cca612fcb858f964..2a5511f8648b6142b5858f2a065126842a9db244 100644 (file)
 #ifndef _GEOMImpl_IImportExportOperations_HXX_
 #define _GEOMImpl_IImportExportOperations_HXX_
 
+#include <list>
+
 #include <Utils_SALOME_Exception.hxx>
 #include "GEOM_IOperations.hxx"
 #include "GEOM_Engine.hxx"
 #include "GEOM_Object.hxx"
 
-#include <list>
+#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
index fa6cd11ebb4df9be0dd46692b7d9f36d1c9efd9f..8fca1ad097e0b06adbcfb5fa2427f15ef400e171 100644 (file)
@@ -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();
 }
+
index 517d576242d81d42abc274b1306e0fd34b113c65..085c7bd9021d3ff8277e33fd613d545b27dde2a4 100644 (file)
@@ -53,6 +53,7 @@ private:
 private:
     QLineEdit* ledFileName;
     QPushButton* btnFileSelect;
+    GEOM::GEOM_Object_var m_mainShape;
 
 private slots:
     void ClickOnOk();