Salome HOME
bos #16700 [EDF] GEOM : Import python file after dump of explode structure from XAO...
[modules/geom.git] / src / XAOPlugin / XAOPlugin_IOperations.cxx
index d8c886274f57b19a6f7af9d30444b4f41ad78052..f725f43b7b66ba8d1cdab859d69b65a30498cd91 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 #include <Utils_SALOME_Exception.hxx>
 
 // GEOM includes
-#include "GEOM_PythonDump.hxx"
-#include "GEOMImpl_Types.hxx"
-#include "GEOMImpl_IGroupOperations.hxx"
-#include "GEOMImpl_IShapesOperations.hxx"
-#include "GEOMImpl_IFieldOperations.hxx"
-#include "GEOM_ISubShape.hxx"
+#include <GEOM_PythonDump.hxx>
+#include <GEOMImpl_Types.hxx>
+#include <GEOMImpl_IGroupOperations.hxx>
+#include <GEOMImpl_IShapesOperations.hxx>
+#include <GEOMImpl_IFieldOperations.hxx>
+#include <GEOM_ISubShape.hxx>
+#include <GEOM_Object.hxx>
+#include <GEOM_Field.hxx>
 
 #include <XAO_Geometry.hxx>
 #include <XAO_BrepGeometry.hxx>
@@ -97,8 +99,8 @@ TopAbs_ShapeEnum getGroupDimension(XAO::Group* group)
  *  Constructor
  */
 //=============================================================================
-XAOPlugin_IOperations::XAOPlugin_IOperations( GEOM_Engine* theEngine, int theDocID )
-: GEOMImpl_IBaseIEOperations( theEngine, theDocID )
+XAOPlugin_IOperations::XAOPlugin_IOperations( GEOM_Engine* theEngine )
+: GEOMImpl_IBaseIEOperations( theEngine )
 {
   MESSAGE( "XAOPlugin_IOperations::XAOPlugin_IOperations" );
 }
@@ -113,15 +115,19 @@ XAOPlugin_IOperations::~XAOPlugin_IOperations()
   MESSAGE( "XAOPlugin_IOperations::~XAOPlugin_IOperations" );
 }
 
-void XAOPlugin_IOperations::exportGroups( std::list<Handle(GEOM_Object)> groupList,
-                                                  XAO::Xao* xaoObject,
-                                                  XAO::BrepGeometry* geometry )
+bool XAOPlugin_IOperations::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++);
+    if (currGroup->GetType() != GEOM_GROUP) {
+      SetErrorCode("Error when export groups: you could perform this operation only with group.");
+      return false;
+    }
     Handle(TColStd_HArray1OfInteger) groupIds = myGroupOperations->GetObjects(currGroup);
 
     TopAbs_ShapeEnum shapeGroup = myGroupOperations->GetType(currGroup);
@@ -164,11 +170,12 @@ void XAOPlugin_IOperations::exportGroups( std::list<Handle(GEOM_Object)> groupLi
       break;
     }
   }
+  return true;
 }
 
 void XAOPlugin_IOperations::exportFields( std::list<Handle(GEOM_Field)> fieldList,
-                                                  XAO::Xao* xaoObject,
-                                                  XAO::BrepGeometry* geometry )
+                                          XAO::Xao* xaoObject,
+                                          XAO::BrepGeometry* geometry )
 {
   std::list<Handle(GEOM_Field)>::iterator fieldIterator = fieldList.begin();
   while (fieldIterator != fieldList.end())
@@ -301,10 +308,11 @@ void XAOPlugin_IOperations::exportSubshapes( const Handle(GEOM_Object)& shape, X
  */
 //=============================================================================
 bool XAOPlugin_IOperations::ExportXAO( Handle(GEOM_Object) shape,
-                                      std::list<Handle(GEOM_Object)> groupList,
-                                      std::list<Handle(GEOM_Field)> fieldList,
-                                      const char* author,
-                                      const char* fileName )
+                                       std::list<Handle(GEOM_Object)> groupList,
+                                       std::list<Handle(GEOM_Field)> fieldList,
+                                       const char* author,
+                                       const char* fileName,
+                                       const char* shapeFileName )
 {
   SetErrorCode(KO);
 
@@ -315,7 +323,7 @@ bool XAOPlugin_IOperations::ExportXAO( Handle(GEOM_Object) shape,
   if (lastFunction.IsNull()) return false;
 
   // add a new result object
-  Handle(GEOM_Object) result = GetEngine()->AddObject(GetDocID(), GEOM_IMPORT);
+  Handle(GEOM_Object) result = GetEngine()->AddObject(GEOM_IMPORT);
 
   // add an Export function
   Handle(GEOM_Function) exportFunction = result->AddFunction(XAOPlugin_Driver::GetID(), EXPORT_SHAPE);
@@ -337,11 +345,11 @@ bool XAOPlugin_IOperations::ExportXAO( Handle(GEOM_Object) shape,
   exportSubshapes(shape, geometry);
   xaoObject->setGeometry(geometry);
 
-  exportGroups(groupList, xaoObject, geometry);
+  if (!exportGroups(groupList, xaoObject, geometry)) return false;
   exportFields(fieldList, xaoObject, geometry);
 
   // export the XAO to the file
-  xaoObject->exportXAO(fileName);
+  xaoObject->exportXAO(fileName, shapeFileName);
 
   // make a Python command
   GEOM::TPythonDump pd(exportFunction);
@@ -371,7 +379,7 @@ bool XAOPlugin_IOperations::ExportXAO( Handle(GEOM_Object) shape,
     }
   }
   pd << "], ";
-  pd << "\"" << author << "\", \"" << fileName << "\")";
+  pd << "\"" << author << "\", \"" << fileName << "\", \"" << shapeFileName << "\")";
 
   SetErrorCode(OK);
   delete xaoObject;
@@ -380,8 +388,8 @@ bool XAOPlugin_IOperations::ExportXAO( Handle(GEOM_Object) shape,
 }
 
 void XAOPlugin_IOperations::importSubShapes( XAO::Geometry* xaoGeometry,
-                                                     Handle(GEOM_Function) function, int shapeType, int dim,
-                                                     Handle(TColStd_HSequenceOfTransient)& subShapeList )
+                                             Handle(GEOM_Function) function, int shapeType, int dim,
+                                             Handle(TColStd_HSequenceOfTransient)& subShapeList )
 {
   Handle(GEOM_Object) subShape;
   Handle(GEOM_Function) aFunction;
@@ -401,7 +409,7 @@ void XAOPlugin_IOperations::importSubShapes( XAO::Geometry* xaoGeometry,
     anArray = new TColStd_HArray1OfInteger(1, 1);
     anArray->SetValue(1, iref);
 
-    subShape = GetEngine()->AddObject(GetDocID(), GEOM_SUBSHAPE);
+    subShape = GetEngine()->AddObject(GEOM_SUBSHAPE);
     Handle(GEOM_Function) aFunction = subShape->AddFunction(GEOM_Object::GetSubShapeID(), 1);
     if (aFunction.IsNull())
       return;
@@ -433,10 +441,10 @@ void XAOPlugin_IOperations::importSubShapes( XAO::Geometry* xaoGeometry,
  */
 //=============================================================================
 bool XAOPlugin_IOperations::ImportXAO( const char* fileName,
-                                               Handle(GEOM_Object)& shape,
-                                               Handle(TColStd_HSequenceOfTransient)& subShapes,
-                                               Handle(TColStd_HSequenceOfTransient)& groups,
-                                               Handle(TColStd_HSequenceOfTransient)& fields )
+                                       Handle(GEOM_Object)& shape,
+                                       Handle(TColStd_HSequenceOfTransient)& subShapes,
+                                       Handle(TColStd_HSequenceOfTransient)& groups,
+                                       Handle(TColStd_HSequenceOfTransient)& fields )
 {
   SetErrorCode(KO);
 
@@ -465,7 +473,7 @@ bool XAOPlugin_IOperations::ImportXAO( const char* fileName,
   }
 
   // create the shape
-  shape = GetEngine()->AddObject(GetDocID(), GEOM_IMPORT);
+  shape = GetEngine()->AddObject(GEOM_IMPORT);
   Handle(GEOM_Function) function = shape->AddFunction(XAOPlugin_Driver::GetID(), IMPORT_SHAPE);
   if (function.IsNull()) return false;
   if (function->GetDriverGUID() != XAOPlugin_Driver::GetID()) return false;
@@ -519,8 +527,6 @@ bool XAOPlugin_IOperations::ImportXAO( const char* fileName,
     TDF_Label freeLabel = group->GetFreeLabel();
     TDataStd_Integer::Set(freeLabel, (Standard_Integer) getGroupDimension(xaoGroup));
     groups->Append(group);
-
-    function = group->GetLastFunction();
   }
 
   // create the fields