X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXAOPlugin%2FXAOPlugin_IOperations.cxx;h=865ead17a22f433a435d01b3a00585349c59b33d;hb=c1d63ef1f803d255b61ee99fb618bf471add07f4;hp=d8c886274f57b19a6f7af9d30444b4f41ad78052;hpb=2735fef8fc422fd39a59490e6bb22f2a650d5f5e;p=modules%2Fgeom.git diff --git a/src/XAOPlugin/XAOPlugin_IOperations.cxx b/src/XAOPlugin/XAOPlugin_IOperations.cxx index d8c886274..865ead17a 100644 --- a/src/XAOPlugin/XAOPlugin_IOperations.cxx +++ b/src/XAOPlugin/XAOPlugin_IOperations.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2015 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2014-2023 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 @@ -23,16 +23,19 @@ #include "XAOPlugin_IImportExport.hxx" // KERNEL includes +#include #include #include // 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 +#include +#include +#include +#include +#include +#include +#include #include #include @@ -53,6 +56,7 @@ #include #include +#include XAO::Dimension shapeEnumToDimension(const TopAbs_ShapeEnum& shape) { @@ -97,8 +101,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,21 +117,28 @@ XAOPlugin_IOperations::~XAOPlugin_IOperations() MESSAGE( "XAOPlugin_IOperations::~XAOPlugin_IOperations" ); } -void XAOPlugin_IOperations::exportGroups( std::list groupList, - XAO::Xao* xaoObject, - XAO::BrepGeometry* geometry ) +bool XAOPlugin_IOperations::exportGroups( std::list groupList, + XAO::Xao* xaoObject, + XAO::BrepGeometry* geometry ) { // add the groups std::list::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); XAO::Dimension dim = shapeEnumToDimension(shapeGroup); XAO::Group* group = xaoObject->addGroup(dim, currGroup->GetName().ToCString()); + // Group can be empty + if (groupIds.IsNull()) continue; + switch (shapeGroup) { case TopAbs_VERTEX: @@ -162,13 +173,16 @@ void XAOPlugin_IOperations::exportGroups( std::list groupLi group->add(index); } break; + default: + ; } } + return true; } void XAOPlugin_IOperations::exportFields( std::list fieldList, - XAO::Xao* xaoObject, - XAO::BrepGeometry* geometry ) + XAO::Xao* xaoObject, + XAO::BrepGeometry* /*geometry*/ ) { std::list::iterator fieldIterator = fieldList.begin(); while (fieldIterator != fieldList.end()) @@ -260,6 +274,13 @@ void XAOPlugin_IOperations::exportSubshapes( const Handle(GEOM_Object)& shape, X { Handle(TColStd_HSequenceOfTransient) subObjects = myShapesOperations->GetExistingSubObjects( shape, GEOMImpl_IShapesOperations::SubShapes ); int nbSubObjects = subObjects->Length(); + if (!nbSubObjects) return; + + TopoDS_Shape aMainShape = shape->GetValue(); + if (aMainShape.IsNull()) return; + TopTools_IndexedMapOfShape anIndices; + TopExp::MapShapes(aMainShape, anIndices); + // set the names of the sub shapes for (int i = 1; i <= nbSubObjects; i++) { @@ -270,8 +291,16 @@ void XAOPlugin_IOperations::exportSubshapes( const Handle(GEOM_Object)& shape, X Handle(GEOM_Object) subObject = Handle(GEOM_Object)::DownCast( transientSubObject ); if (subObject->GetType() != GEOM_GROUP) { - int subIndex = myShapesOperations->GetSubShapeIndex( shape, subObject ); - switch (subObject->GetValue().ShapeType()) + TopoDS_Shape aSubShape = subObject->GetValue(); + if (aSubShape.IsNull()) continue; + + // Do not call GEOMImpl_IShapesOperations::GetSubShapeIndex() here + // for time optimization reason (it invokes TopExp::MapShapes()) + //int subIndex = myShapesOperations->GetSubShapeIndex( shape, subObject ); + int subIndex = anIndices.FindIndex(aSubShape); + if (!subIndex) continue; + + switch (aSubShape.ShapeType()) { case TopAbs_VERTEX: geometry->changeVertexName(subIndex, subObject->GetName().ToCString()); @@ -285,6 +314,8 @@ void XAOPlugin_IOperations::exportSubshapes( const Handle(GEOM_Object)& shape, X case TopAbs_SOLID: geometry->changeSolidName(subIndex, subObject->GetName().ToCString()); break; + default: + ; } } } @@ -301,10 +332,11 @@ void XAOPlugin_IOperations::exportSubshapes( const Handle(GEOM_Object)& shape, X */ //============================================================================= bool XAOPlugin_IOperations::ExportXAO( Handle(GEOM_Object) shape, - std::list groupList, - std::list fieldList, - const char* author, - const char* fileName ) + std::list groupList, + std::list fieldList, + const char* author, + const char* fileName, + const char* shapeFileName ) { SetErrorCode(KO); @@ -315,7 +347,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,14 +369,15 @@ 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); + std::string convFileName = Kernel_Utils::BackSlashToSlash(fileName); pd << "exported = geompy.ExportXAO(" << shape; // list of groups @@ -371,7 +404,7 @@ bool XAOPlugin_IOperations::ExportXAO( Handle(GEOM_Object) shape, } } pd << "], "; - pd << "\"" << author << "\", \"" << fileName << "\")"; + pd << "\"" << author << "\", \"" << convFileName.c_str() << "\", \"" << shapeFileName << "\")"; SetErrorCode(OK); delete xaoObject; @@ -380,8 +413,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 +434,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 +466,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 +498,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; @@ -501,13 +534,19 @@ bool XAOPlugin_IOperations::ImportXAO( const char* fileName, // build an array with the indexes of the sub shapes int nbElt = xaoGroup->count(); - Handle(TColStd_HArray1OfInteger) array = new TColStd_HArray1OfInteger(1, nbElt); - int j = 0; - for (std::set::iterator it = xaoGroup->begin(); it != xaoGroup->end(); ++it) - { - int index = (*it); - std::string ref = xaoGeometry->getElementReference(xaoGroup->getDimension(), index); - array->SetValue(++j, XAO::XaoUtils::stringToInt(ref)); + Handle(TColStd_HArray1OfInteger) array; + if (nbElt > 0) { + array = new TColStd_HArray1OfInteger(1, nbElt); + int j = 0; + for (std::set::iterator it = xaoGroup->begin(); it != xaoGroup->end(); ++it) { + int index = (*it); + std::string ref = xaoGeometry->getElementReference(xaoGroup->getDimension(), index); + array->SetValue(++j, XAO::XaoUtils::stringToInt(ref)); + } + } + else { // empty group + array = new TColStd_HArray1OfInteger(1, 1); + array->SetValue(1, -1); } // create the group with the array of sub shapes indexes @@ -519,8 +558,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 @@ -658,8 +695,9 @@ bool XAOPlugin_IOperations::ImportXAO( const char* fileName, pd << obj << ((i < nbFields) ? ", " : ""); } } + std::string convFileName = Kernel_Utils::BackSlashToSlash( fileName ); pd << "]"; - pd << ") = geompy.ImportXAO(\"" << fileName << "\")"; + pd << ") = geompy.ImportXAO(\"" << convFileName.c_str() << "\")"; delete xaoObject; SetErrorCode(OK);