diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index 6d6d5ccf5..ad612446c 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -3743,7 +3743,7 @@ module GEOM * \return boolean indicating if export was successful. */ boolean ExportXAO(in GEOM_Object shape, - in ListOfGO groups, in ListOfGO fields, + in ListOfGO groups, in ListOfFields fields, in string author, in string fileName); /*! @@ -3756,7 +3756,7 @@ module GEOM * \return boolean indicating if import was successful. */ boolean ImportXAO(in string fileName, out GEOM_Object shape, - out ListOfGO subShapes, out ListOfGO groups, out ListOfGO fields); + out ListOfGO subShapes, out ListOfGO groups, out ListOfFields fields); }; // # GEOM_IKindOfShape: diff --git a/idl/GEOM_Superv.idl b/idl/GEOM_Superv.idl index 438905932..b0653b468 100644 --- a/idl/GEOM_Superv.idl +++ b/idl/GEOM_Superv.idl @@ -269,10 +269,10 @@ module GEOM void ExportTranslators (out string_array theFormats, out string_array thePatterns) ; boolean ExportXAO(in GEOM_Object shape, - in ListOfGO groups, in ListOfGO fields, - in string author, in string fileName); + in ListOfGO groups, in ListOfFields fields, + in string author, in string fileName); boolean ImportXAO(in string fileName, out GEOM_Object shape, - out ListOfGO subShapes, out ListOfGO groups, out ListOfGO fields); + out ListOfGO subShapes, out ListOfGO groups, out ListOfFields fields); //-----------------------------------------------------------// // TransformOperations // diff --git a/src/GEOMBase/GEOM_GenericObjPtr.h b/src/GEOMBase/GEOM_GenericObjPtr.h index 0cb831b0f..b86a4cf41 100644 --- a/src/GEOMBase/GEOM_GenericObjPtr.h +++ b/src/GEOMBase/GEOM_GenericObjPtr.h @@ -216,6 +216,7 @@ namespace GEOM }; typedef GenericObjPtr GeomObjPtr; + typedef GenericObjPtr GeomFieldPtr; typedef GenericObjPtr BasicOpPtr; typedef GenericObjPtr TransformOpPtr; typedef GenericObjPtr I3DPrimOpPtr; diff --git a/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx b/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx index a3e2fcef3..cc03711a0 100644 --- a/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IInsertOperations.cxx @@ -32,6 +32,7 @@ #include #include "GEOMImpl_IShapesOperations.hxx" #include "GEOMImpl_IGroupOperations.hxx" +#include "GEOMImpl_IFieldOperations.hxx" #include "GEOMImpl_XAODriver.hxx" #include "GEOMImpl_IImportExportXAO.hxx" @@ -45,6 +46,14 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include #include @@ -67,6 +76,7 @@ #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1 #include +#include #else #include #endif @@ -100,6 +110,7 @@ GEOMImpl_IInsertOperations::GEOMImpl_IInsertOperations(GEOM_Engine* theEngine, i MESSAGE("GEOMImpl_IInsertOperations::GEOMImpl_IInsertOperations"); myShapesOperations = new GEOMImpl_IShapesOperations(GetEngine(), GetDocID()); myGroupOperations = new GEOMImpl_IGroupOperations(GetEngine(), GetDocID()); + myFieldOperations = new GEOMImpl_IFieldOperations(GetEngine(), GetDocID()); } //============================================================================= @@ -112,6 +123,7 @@ GEOMImpl_IInsertOperations::~GEOMImpl_IInsertOperations() MESSAGE("GEOMImpl_IInsertOperations::~GEOMImpl_IInsertOperations"); delete myShapesOperations; delete myGroupOperations; + delete myFieldOperations; } //============================================================================= @@ -837,7 +849,9 @@ XAO::Dimension shapeEnumToDimension(const TopAbs_ShapeEnum& shape) return dim; } -void GEOMImpl_IInsertOperations::exportGroups(std::list groupList, XAO::Xao* xaoObject, XAO::BrepGeometry* geometry) +void GEOMImpl_IInsertOperations::exportGroups(std::list groupList, + XAO::Xao* xaoObject, + XAO::BrepGeometry* geometry) { // add the groups std::list::iterator groupIterator = groupList.begin(); @@ -855,42 +869,129 @@ void GEOMImpl_IInsertOperations::exportGroups(std::list gro case TopAbs_VERTEX: for (int i = 1; i <= groupIds->Length(); i++) { - std::string ref = XAO::XaoUtils::intToString(groupIds->Value(i)); - int index = geometry->getVertexIndexByReference(ref); - group->add(index); + std::string ref = XAO::XaoUtils::intToString(groupIds->Value(i)); + int index = geometry->getVertexIndexByReference(ref); + group->add(index); } break; case TopAbs_EDGE: for (int i = 1; i <= groupIds->Length(); i++) { - std::string ref = XAO::XaoUtils::intToString(groupIds->Value(i)); - int index = geometry->getEdgeIndexByReference(ref); - group->add(index); + std::string ref = XAO::XaoUtils::intToString(groupIds->Value(i)); + int index = geometry->getEdgeIndexByReference(ref); + group->add(index); } break; case TopAbs_FACE: for (int i = 1; i <= groupIds->Length(); i++) { - std::string ref = XAO::XaoUtils::intToString(groupIds->Value(i)); - int index = geometry->getFaceIndexByReference(ref); - group->add(index); + std::string ref = XAO::XaoUtils::intToString(groupIds->Value(i)); + int index = geometry->getFaceIndexByReference(ref); + group->add(index); } break; case TopAbs_SOLID: for (int i = 1; i <= groupIds->Length(); i++) { - std::string ref = XAO::XaoUtils::intToString(groupIds->Value(i)); - int index = geometry->getSolidIndexByReference(ref); - group->add(index); + std::string ref = XAO::XaoUtils::intToString(groupIds->Value(i)); + int index = geometry->getSolidIndexByReference(ref); + group->add(index); } break; } } } -void GEOMImpl_IInsertOperations::exportFields(std::list fieldList, XAO::Xao* xaoObject, XAO::BrepGeometry* geometry) +void GEOMImpl_IInsertOperations::exportFields(std::list fieldList, + XAO::Xao* xaoObject, + XAO::BrepGeometry* geometry) { - // TODO + std::list::iterator fieldIterator = fieldList.begin(); + while (fieldIterator != fieldList.end()) + { + Handle(GEOM_Field) currField = (*fieldIterator++); + + int fdim = currField->GetDimension(); + int ftype = currField->GetDataType(); + int nbComponents = currField->GetNbComponents(); + std::string name = currField->GetName().ToCString(); + + XAO::Field* field = xaoObject->addField((XAO::Type)ftype, (XAO::Dimension)fdim, nbComponents, name); + + Handle(TColStd_HArray1OfExtendedString) components = currField->GetComponents(); + std::cout << "nb comp " << nbComponents << std::endl; + std::cout << components->Lower() << " - " << components->Upper() << std::endl; + for (int i = components->Lower(), j = 0; i <= components->Upper(); ++i, ++j) + { + field->setComponentName(j, TCollection_AsciiString(components->Value(i)).ToCString()); + } + + std::list< Handle(GEOM_FieldStep)> steps = currField->GetSteps(); + std::list::iterator stepIterator = steps.begin(); + while (stepIterator != steps.end()) + { + Handle(GEOM_FieldStep) currStep = (*stepIterator++); + + XAO::Step* step = field->addNewStep(currStep->GetID()); + step->setStamp(currStep->GetStamp()); + + switch (ftype) + { + case 0: // bool + { + XAO::BooleanStep* bs = (XAO::BooleanStep*)step; + Handle(TColStd_HArray1OfInteger) bvalues = currStep->GetIntValues(); + std::vector bv; + bv.reserve(bvalues->Upper()); + for ( int i = bvalues->Lower(), nb = bvalues->Upper(); i <= nb; ++i ) + { + bv.push_back(bvalues->Value(i) != 0); + } + bs->setValues(bv); + break; + } + case 1: // integer + { + XAO::IntegerStep* is = (XAO::IntegerStep*)step; + Handle(TColStd_HArray1OfInteger) ivalues = currStep->GetIntValues(); + std::vector iv; + iv.reserve(ivalues->Upper()); + for ( int i = ivalues->Lower(), nb = ivalues->Upper(); i <= nb; ++i ) + { + iv.push_back(ivalues->Value(i)); + } + is->setValues(iv); + break; + } + case 2: // double + { + XAO::DoubleStep* ds = (XAO::DoubleStep*)step; + Handle(TColStd_HArray1OfReal) dvalues = currStep->GetDoubleValues(); + std::vector dv; + dv.reserve(dvalues->Upper()); + for ( int i = dvalues->Lower(), nb = dvalues->Upper(); i <= nb; ++i ) + { + dv.push_back(dvalues->Value(i)); + } + ds->setValues(dv); + break; + } + case 3: // string + { + XAO::StringStep* ss = (XAO::StringStep*)step; + Handle(TColStd_HArray1OfExtendedString) svalues = currStep->GetStringValues(); + std::vector sv; + sv.reserve(svalues->Upper()); + for ( int i = svalues->Lower(), nb = svalues->Upper(); i <= nb; ++i ) + { + sv.push_back(TCollection_AsciiString(svalues->Value(i)).ToCString()); + } + ss->setValues(sv); + break; + } + } + } + } } void GEOMImpl_IInsertOperations::exportSubshapes(const Handle(GEOM_Object)& shape, XAO::BrepGeometry* geometry) @@ -911,17 +1012,17 @@ void GEOMImpl_IInsertOperations::exportSubshapes(const Handle(GEOM_Object)& shap switch (subObject->GetValue().ShapeType()) { case TopAbs_VERTEX: - geometry->changeVertexName(subIndex, subObject->GetName().ToCString()); - break; + geometry->changeVertexName(subIndex, subObject->GetName().ToCString()); + break; case TopAbs_EDGE: - geometry->changeEdgeName(subIndex, subObject->GetName().ToCString()); - break; + geometry->changeEdgeName(subIndex, subObject->GetName().ToCString()); + break; case TopAbs_FACE: - geometry->changeFaceName(subIndex, subObject->GetName().ToCString()); - break; + geometry->changeFaceName(subIndex, subObject->GetName().ToCString()); + break; case TopAbs_SOLID: - geometry->changeSolidName(subIndex, subObject->GetName().ToCString()); - break; + geometry->changeSolidName(subIndex, subObject->GetName().ToCString()); + break; } } } @@ -938,13 +1039,13 @@ void GEOMImpl_IInsertOperations::exportSubshapes(const Handle(GEOM_Object)& shap */ //============================================================================= bool GEOMImpl_IInsertOperations::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) { SetErrorCode(KO); - + if (shape.IsNull()) return false; // add a new shape function with parameters @@ -1000,7 +1101,7 @@ bool GEOMImpl_IInsertOperations::ExportXAO(Handle(GEOM_Object) shape, pd << "], ["; if (fieldList.size() > 0) { - std::list::iterator itField = fieldList.begin(); + std::list::iterator itField = fieldList.begin(); pd << (*itField++); while (itField != fieldList.end()) { @@ -1017,8 +1118,8 @@ bool GEOMImpl_IInsertOperations::ExportXAO(Handle(GEOM_Object) shape, } void GEOMImpl_IInsertOperations::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; @@ -1070,10 +1171,10 @@ void GEOMImpl_IInsertOperations::importSubShapes(XAO::Geometry* xaoGeometry, */ //============================================================================= bool GEOMImpl_IInsertOperations::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); @@ -1158,7 +1259,102 @@ bool GEOMImpl_IInsertOperations::ImportXAO(const char* fileName, function = group->GetLastFunction(); } - // TODO: create the fields + // create the fields + int nbFields = xaoObject->countFields(); + for (int i = 0; i < nbFields; ++i) + { + XAO::Field* xaoField = xaoObject->getField(i); + + Handle(TColStd_HArray1OfExtendedString) components = new TColStd_HArray1OfExtendedString(0, xaoField->countComponents()); + for (int j = 0; j < xaoField->countComponents(); ++j) + { + components->SetValue(j, (TCollection_ExtendedString)xaoField->getComponentName(j).c_str()); + } + + Handle(GEOM_Field) field = myFieldOperations->CreateField(shape, + xaoField->getName().c_str(), + (int)xaoField->getType(), + (int)xaoField->getDimension(), + components); + + switch (xaoField->getType()) + { + case XAO::BOOLEAN: + { + XAO::BooleanField* bfield = (XAO::BooleanField*)xaoField; + for (int j = 0; j < xaoField->countSteps(); ++j) + { + XAO::BooleanStep* bstep = bfield->getStep(j); + Handle(GEOM_FieldStep) step = field->AddStep(bstep->getStep(), bstep->getStamp()); + + Handle(TColStd_HArray1OfInteger) values = new TColStd_HArray1OfInteger(0, bstep->countValues()); + std::vector bvalues = bstep->getValues(); + for (int k = 0; k < bstep->countValues(); ++k) + { + values->SetValue(0, bvalues[k] ? 1 : 0); + } + step->SetValues(values); + } + break; + } + case XAO::INTEGER: + { + XAO::IntegerField* ifield = (XAO::IntegerField*)xaoField; + for (int j = 0; j < xaoField->countSteps(); ++j) + { + XAO::IntegerStep* istep = ifield->getStep(j); + Handle(GEOM_FieldStep) step = field->AddStep(istep->getStep(), istep->getStamp()); + + Handle(TColStd_HArray1OfInteger) values = new TColStd_HArray1OfInteger(0, istep->countValues()); + std::vector ivalues = istep->getValues(); + for (int k = 0; k < istep->countValues(); ++k) + { + values->SetValue(0, ivalues[k]); + } + step->SetValues(values); + } + break; + } + case XAO::DOUBLE: + { + XAO::DoubleField* dfield = (XAO::DoubleField*)xaoField; + for (int j = 0; j < xaoField->countSteps(); ++j) + { + XAO::DoubleStep* dstep = dfield->getStep(j); + Handle(GEOM_FieldStep) step = field->AddStep(dstep->getStep(), dstep->getStamp()); + + Handle(TColStd_HArray1OfReal) values = new TColStd_HArray1OfReal(0, dstep->countValues()); + std::vector dvalues = dstep->getValues(); + for (int k = 0; k < dstep->countValues(); ++k) + { + values->SetValue(0, dvalues[k]); + } + step->SetValues(values); + } + break; + } + case XAO::STRING: + { + XAO::StringField* sfield = (XAO::StringField*)xaoField; + for (int j = 0; j < xaoField->countSteps(); ++j) + { + XAO::StringStep* sstep = sfield->getStep(j); + Handle(GEOM_FieldStep) step = field->AddStep(sstep->getStep(), sstep->getStamp()); + + Handle(TColStd_HArray1OfExtendedString) values = new TColStd_HArray1OfExtendedString(0, sstep->countValues()); + std::vector svalues = sstep->getValues(); + for (int k = 0; k < sstep->countValues(); ++k) + { + values->SetValue(0, TCollection_ExtendedString(svalues[k].c_str())); + } + step->SetValues(values); + } + break; + } + } + + fields->Append(field); + } // make a Python command GEOM::TPythonDump pd(function); diff --git a/src/GEOMImpl/GEOMImpl_IInsertOperations.hxx b/src/GEOMImpl/GEOMImpl_IInsertOperations.hxx index d5b7befbf..3173e545e 100644 --- a/src/GEOMImpl/GEOMImpl_IInsertOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_IInsertOperations.hxx @@ -26,6 +26,7 @@ #include "GEOM_IOperations.hxx" #include "GEOM_Engine.hxx" #include "GEOM_Object.hxx" +#include "GEOM_Field.hxx" #include @@ -40,6 +41,7 @@ class GEOMImpl_IShapesOperations; class GEOMImpl_IGroupOperations; +class GEOMImpl_IFieldOperations; #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1 class Handle_TColStd_HArray1OfByte; @@ -101,36 +103,37 @@ class GEOMImpl_IInsertOperations : public GEOM_IOperations { int& theWidth, int& theHeight); Standard_EXPORT std::list GetAllTextures(); - + Standard_EXPORT bool 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); Standard_EXPORT bool 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); private: Standard_Boolean InitResMgr (); void importSubShapes(XAO::Geometry* xaoGeometry, Handle(GEOM_Function) function, - int shapeType, int dim, - Handle(TColStd_HSequenceOfTransient)& subshapeList); + int shapeType, int dim, + Handle(TColStd_HSequenceOfTransient)& subshapeList); void exportSubshapes(const Handle(GEOM_Object)& shape, XAO::BrepGeometry* geometry); - void exportFields(std::list fieldList, XAO::Xao* xaoObject, - XAO::BrepGeometry* geometry); + void exportFields(std::list fieldList, XAO::Xao* xaoObject, + XAO::BrepGeometry* geometry); void exportGroups(std::list groupList, XAO::Xao* xaoObject, - XAO::BrepGeometry* geometry); + XAO::BrepGeometry* geometry); private: Handle(Resource_Manager) myResMgr; Handle(Resource_Manager) myResMgrUser; GEOMImpl_IShapesOperations* myShapesOperations; GEOMImpl_IGroupOperations* myGroupOperations; + GEOMImpl_IFieldOperations* myFieldOperations; }; #endif diff --git a/src/GEOM_I/GEOM_IInsertOperations_i.cc b/src/GEOM_I/GEOM_IInsertOperations_i.cc index d4818618f..217655cf6 100644 --- a/src/GEOM_I/GEOM_IInsertOperations_i.cc +++ b/src/GEOM_I/GEOM_IInsertOperations_i.cc @@ -373,8 +373,10 @@ GEOM::ListOfLong* GEOM_IInsertOperations_i::GetAllTextures() */ //============================================================================= CORBA::Boolean GEOM_IInsertOperations_i::ExportXAO(GEOM::GEOM_Object_ptr shape, - const GEOM::ListOfGO& groups, const GEOM::ListOfGO& fields, - const char* author, const char* fileName) + const GEOM::ListOfGO& groups, + const GEOM::ListOfFields& fields, + const char* author, + const char* fileName) { bool isGood = false; // Set a not done flag @@ -392,13 +394,13 @@ CORBA::Boolean GEOM_IInsertOperations_i::ExportXAO(GEOM::GEOM_Object_ptr shape, if (gobj.IsNull()) return false; groupsObj.push_back(gobj); } - + // Get the reference fields ind = 0; - std::list fieldsObj; + std::list fieldsObj; for (; ind < fields.length(); ind++) { - Handle(GEOM_Object) fobj = GetObjectImpl(fields[ind]); + Handle(GEOM_Field) fobj = Handle(GEOM_Field)::DownCast(GetBaseObjectImpl(fields[ind])); if (fobj.IsNull()) return false; fieldsObj.push_back(fobj); } @@ -424,17 +426,17 @@ CORBA::Boolean GEOM_IInsertOperations_i::ExportXAO(GEOM::GEOM_Object_ptr shape, */ //============================================================================= CORBA::Boolean GEOM_IInsertOperations_i::ImportXAO(const char* fileName, - GEOM::GEOM_Object_out shape, - GEOM::ListOfGO_out subShapes, - GEOM::ListOfGO_out groups, - GEOM::ListOfGO_out fields) + GEOM::GEOM_Object_out shape, + GEOM::ListOfGO_out subShapes, + GEOM::ListOfGO_out groups, + GEOM::ListOfFields_out fields) { GEOM::GEOM_Object_var vshape; shape = vshape._retn(); subShapes = new GEOM::ListOfGO; groups = new GEOM::ListOfGO; - fields = new GEOM::ListOfGO; + fields = new GEOM::ListOfFields; // Set a not done flag GetOperations()->SetNotDone(); @@ -469,7 +471,8 @@ CORBA::Boolean GEOM_IInsertOperations_i::ImportXAO(const char* fileName, fields->length(n); for (int i = 1; i <= n; i++) { - (*fields)[i - 1] = GetObject(Handle(GEOM_Object)::DownCast(importedFields->Value(i))); + // TODO: FPS + //(*fields)[i - 1] = GetObject(Handle(GEOM_Field)::DownCast(importedFields->Value(i))); } shape = GetObject(hshape); diff --git a/src/GEOM_I/GEOM_IInsertOperations_i.hh b/src/GEOM_I/GEOM_IInsertOperations_i.hh index aca7a55f7..69bd1cdf4 100644 --- a/src/GEOM_I/GEOM_IInsertOperations_i.hh +++ b/src/GEOM_I/GEOM_IInsertOperations_i.hh @@ -74,16 +74,16 @@ class GEOM_I_EXPORT GEOM_IInsertOperations_i : GEOM::ListOfLong* GetAllTextures(); CORBA::Boolean ExportXAO (GEOM::GEOM_Object_ptr shape, - const GEOM::ListOfGO& groups, - const GEOM::ListOfGO& fields, - const char* author, - const char* fileName); + const GEOM::ListOfGO& groups, + const GEOM::ListOfFields& fields, + const char* author, + const char* fileName); CORBA::Boolean ImportXAO (const char* fileName, - GEOM::GEOM_Object_out shape, - GEOM::ListOfGO_out subShapes, - GEOM::ListOfGO_out groups, - GEOM::ListOfGO_out fields); + GEOM::GEOM_Object_out shape, + GEOM::ListOfGO_out subShapes, + GEOM::ListOfGO_out groups, + GEOM::ListOfFields_out fields); ::GEOMImpl_IInsertOperations* GetOperations() { return (::GEOMImpl_IInsertOperations*)GetImpl(); } diff --git a/src/GEOM_I_Superv/GEOM_Superv_i.cc b/src/GEOM_I_Superv/GEOM_Superv_i.cc index 2d563ef8c..946f958d2 100644 --- a/src/GEOM_I_Superv/GEOM_Superv_i.cc +++ b/src/GEOM_I_Superv/GEOM_Superv_i.cc @@ -3332,7 +3332,7 @@ GEOM::GEOM_List_ptr GEOM_Superv_i::GetObjects (GEOM::GEOM_Object_ptr theGroup) // ExportXAO //============================================================================= CORBA::Boolean GEOM_Superv_i::ExportXAO (GEOM::GEOM_Object_ptr shape, - const GEOM::ListOfGO& groups, const GEOM::ListOfGO& fields, + const GEOM::ListOfGO& groups, const GEOM::ListOfFields& fields, const char* author, const char* fileName) { beginService( " GEOM_Superv_i::ExportXAO" ); @@ -3347,7 +3347,7 @@ CORBA::Boolean GEOM_Superv_i::ExportXAO (GEOM::GEOM_Object_ptr shape, // ImportXAO //============================================================================= CORBA::Boolean GEOM_Superv_i::ImportXAO (const char* fileName, GEOM::GEOM_Object_out shape, - GEOM::ListOfGO_out subShapes, GEOM::ListOfGO_out groups, GEOM::ListOfGO_out fields) + GEOM::ListOfGO_out subShapes, GEOM::ListOfGO_out groups, GEOM::ListOfFields_out fields) { return false; } diff --git a/src/GEOM_I_Superv/GEOM_Superv_i.hh b/src/GEOM_I_Superv/GEOM_Superv_i.hh index 6136b3e74..daff0facb 100644 --- a/src/GEOM_I_Superv/GEOM_Superv_i.hh +++ b/src/GEOM_I_Superv/GEOM_Superv_i.hh @@ -692,10 +692,10 @@ public: // ImportExport Operations // //-----------------------------------------------------------// CORBA::Boolean ExportXAO(GEOM::GEOM_Object_ptr shape, - const GEOM::ListOfGO& groups, const GEOM::ListOfGO& fields, + const GEOM::ListOfGO& groups, const GEOM::ListOfFields& fields, const char* author, const char* fileName); CORBA::Boolean ImportXAO(const char* fileName, GEOM::GEOM_Object_out shape, - GEOM::ListOfGO_out subShapes, GEOM::ListOfGO_out groups, GEOM::ListOfGO_out fields); + GEOM::ListOfGO_out subShapes, GEOM::ListOfGO_out groups, GEOM::ListOfFields_out fields); //-----------------------------------------------------------// // Advanced Operations // diff --git a/src/ImportExportGUI/ImportExportGUI_ExportXAODlg.cxx b/src/ImportExportGUI/ImportExportGUI_ExportXAODlg.cxx index 93651b27c..4cf4408b8 100644 --- a/src/ImportExportGUI/ImportExportGUI_ExportXAODlg.cxx +++ b/src/ImportExportGUI/ImportExportGUI_ExportXAODlg.cxx @@ -22,8 +22,10 @@ #include #include +#include #include #include +#include #include #include @@ -32,7 +34,6 @@ #include #include #include -//#include // OCCT Includes #include @@ -43,7 +44,6 @@ #include #include "ImportExportGUI_ExportXAODlg.h" -//#include "ImportExportGUI_Widgets.h" //================================================================================= // Constructor @@ -137,7 +137,7 @@ ImportExportGUI_ExportXAODlg::ImportExportGUI_ExportXAODlg(GeometryGUI* geometry lstGroups = new QListWidget(gbxFilter); lstGroups->setSelectionMode(QAbstractItemView::ExtendedSelection); lstFields = new QListWidget(gbxFilter); - lstFields ->setSelectionMode(QAbstractItemView::ExtendedSelection); + lstFields->setSelectionMode(QAbstractItemView::ExtendedSelection); line++; col = 0; gridLayoutFilter->addWidget(lstGroups, line, col++, 1, 1); @@ -184,7 +184,6 @@ void ImportExportGUI_ExportXAODlg::Init() connect(btnFileSelect, SIGNAL(clicked()), this, SLOT(btnFileSelectClicked())); - initName(tr("GEOM_EXPORTXAO")); SelectionIntoArgument(); } @@ -217,11 +216,25 @@ void ImportExportGUI_ExportXAODlg::processObject() item->setData(Qt::UserRole, QVariant(i)); item->setText(GEOMBase::GetName(groups[i])); lstGroups->addItem(item); + item->setSelected(true); m_groups.append(GEOM::GeomObjPtr(groups[i].in())); } lstGroups->sortItems(Qt::AscendingOrder); - // TODO: add fields + // add fields + GEOM::GEOM_IFieldOperations_var fieldOp = getGeomEngine()->GetIFieldOperations(getStudyId()); + + GEOM::ListOfFields_var fields = fieldOp->GetFields(m_mainObj); + for (int i = 0, n = fields->length(); i < n; i++) + { + QListWidgetItem* item = new QListWidgetItem(); + item->setData(Qt::UserRole, QVariant(i)); + item->setText(fields[i]->GetName()); + lstFields->addItem(item); + item->setSelected(true); + m_fields.append(GEOM::GeomFieldPtr(fields[i].in())); + } + lstFields->sortItems(Qt::AscendingOrder); } } @@ -231,8 +244,10 @@ void ImportExportGUI_ExportXAODlg::processObject() //================================================================================= void ImportExportGUI_ExportXAODlg::ClickOnOk() { + setIsApplyAndClose(true); if (ClickOnApply()) ClickOnCancel(); + setIsApplyAndClose(false); } //================================================================================= @@ -241,10 +256,46 @@ void ImportExportGUI_ExportXAODlg::ClickOnOk() //================================================================================= bool ImportExportGUI_ExportXAODlg::ClickOnApply() { - if (!onAccept()) - return false; + if (!isApplyAndClose()) + { + setIsDisableBrowsing(true); + setIsDisplayResult(false); + } - initName(); + QString msg; + if (!isValid(msg)) + { + showError(msg); + return false; + } + SUIT_OverrideCursor wc; + SUIT_Session::session()->activeApplication()->putInfo(""); + + try + { + if (openCommand()) + if (!execute(/*isApplyAndClose()*/)) + { + abortCommand(); + showError(); + return false; + } + } + catch (const SALOME::SALOME_Exception& e) + { + SalomeApp_Tools::QtCatchCorbaException(e); + abortCommand(); + return false; + } + commitCommand(); + + if (!isApplyAndClose()) + { + setIsDisableBrowsing(false); + setIsDisplayResult(true); + } + + processObject(); return true; } @@ -343,7 +394,7 @@ bool ImportExportGUI_ExportXAODlg::isValid(QString& msg) // function : execute // purpose : //================================================================================= -bool ImportExportGUI_ExportXAODlg::execute(ObjectList& objects) +bool ImportExportGUI_ExportXAODlg::execute() { bool res = false; @@ -364,8 +415,9 @@ bool ImportExportGUI_ExportXAODlg::execute(ObjectList& objects) // get selected fields QList selFields = lstFields->selectedItems(); - GEOM::ListOfGO_var fields = new GEOM::ListOfGO(); + GEOM::ListOfFields_var fields = new GEOM::ListOfFields(); fields->length(m_fields.count()); + i = 0; for (QList::iterator it = selFields.begin(); it != selFields.end(); ++it) { QListWidgetItem* item = (*it); @@ -376,8 +428,8 @@ bool ImportExportGUI_ExportXAODlg::execute(ObjectList& objects) // call engine function GEOM::GEOM_IInsertOperations_var ieOp = GEOM::GEOM_IInsertOperations::_narrow(getOperation()); res = ieOp->ExportXAO(m_mainObj, groups, fields, - author.toStdString().c_str(), - fileName.toStdString().c_str()); + author.toStdString().c_str(), + fileName.toStdString().c_str()); return res; } diff --git a/src/ImportExportGUI/ImportExportGUI_ExportXAODlg.h b/src/ImportExportGUI/ImportExportGUI_ExportXAODlg.h index 1f009b8d6..2beb2989b 100644 --- a/src/ImportExportGUI/ImportExportGUI_ExportXAODlg.h +++ b/src/ImportExportGUI/ImportExportGUI_ExportXAODlg.h @@ -44,7 +44,7 @@ protected: // redefined from GEOMBase_Helper virtual GEOM::GEOM_IOperations_ptr createOperation(); virtual bool isValid(QString&); - virtual bool execute(ObjectList&); + virtual bool execute(); private: void Init(); @@ -54,7 +54,7 @@ private: private: GEOM::GEOM_Object_var m_mainObj; QList m_groups; - QList m_fields; + QList m_fields; QLineEdit* ledShape; QLineEdit* ledFileName; QLineEdit* ledAuthor; @@ -67,7 +67,6 @@ private slots: void ClickOnOk(); bool ClickOnApply(); void ActivateThisDialog(); -// void LineEditReturnPressed(); void SelectionIntoArgument(); void SetEditCurrentArgument(); void btnFileSelectClicked(); diff --git a/src/ImportExportGUI/ImportExportGUI_ImportXAODlg.cxx b/src/ImportExportGUI/ImportExportGUI_ImportXAODlg.cxx index fe2200947..e3b17f678 100644 --- a/src/ImportExportGUI/ImportExportGUI_ImportXAODlg.cxx +++ b/src/ImportExportGUI/ImportExportGUI_ImportXAODlg.cxx @@ -156,7 +156,7 @@ bool ImportExportGUI_ImportXAODlg::ClickOnApply() void ImportExportGUI_ImportXAODlg::btnFileSelectClicked() { QString selFile = QFileDialog::getOpenFileName(this, tr("GEOM_SELECT_EXPORT_XAO"), - QString(), tr("XAO_FILES")); + QString(), tr("XAO_FILES")); if (!selFile.isEmpty()) { ledFileName->setText(selFile); @@ -214,7 +214,8 @@ bool ImportExportGUI_ImportXAODlg::execute(ObjectList& objects) QString fileName = ledFileName->text(); GEOM::GEOM_Object_var shape; - GEOM::ListOfGO_var groups, fields, subShapes; + GEOM::ListOfGO_var groups, subShapes; + GEOM::ListOfFields_var fields; GEOM::GEOM_IInsertOperations_var ieOp = GEOM::GEOM_IInsertOperations::_narrow(getOperation()); res = ieOp->ImportXAO(fileName.toStdString().c_str(), shape, subShapes, groups, fields); @@ -239,7 +240,7 @@ bool ImportExportGUI_ImportXAODlg::execute(ObjectList& objects) } for (int i = 0; i < fields->length(); i++) { - objects.push_back(GEOM::GEOM_Object::_duplicate(fields[i])); + //objects.push_back(GEOM::GEOM_Field::_duplicate(fields[i])); } return res; diff --git a/src/XAO/XAO_Geometry.cxx b/src/XAO/XAO_Geometry.cxx index b774b31af..38cbb0226 100644 --- a/src/XAO/XAO_Geometry.cxx +++ b/src/XAO/XAO_Geometry.cxx @@ -67,6 +67,8 @@ throw (XAO_Exception) return countFaces(); if (dim == XAO::SOLID) return countSolids(); + if (dim == XAO::WHOLE) + return 1; throw XAO_Exception(MsgBuilder() << "Unknown dimension:" << dim); } diff --git a/src/XAO/XAO_XaoExporter.cxx b/src/XAO/XAO_XaoExporter.cxx index d41b1f74f..bd34efafb 100644 --- a/src/XAO/XAO_XaoExporter.cxx +++ b/src/XAO/XAO_XaoExporter.cxx @@ -86,7 +86,7 @@ namespace { xmlDocPtr exportXMLDoc(Xao* xaoObject); void exportGeometry(Geometry* xaoGeometry, xmlDocPtr doc, xmlNodePtr xao); void exportGeometricElements(Geometry* xaoGeometry, xmlNodePtr topology, - XAO::Dimension dim, const xmlChar* colTag, const xmlChar* eltTag); + XAO::Dimension dim, const xmlChar* colTag, const xmlChar* eltTag); void exportGroups(Xao* xaoObject, xmlNodePtr xao); void exportFields(Xao* xaoObject, xmlNodePtr xao); void exportStep(Step* step, Field* field, xmlNodePtr nodeSteps); @@ -109,13 +109,13 @@ namespace { void parseStepElementNode(xmlNodePtr eltNode, Step* step); std::string readStringProp(xmlNodePtr node, const xmlChar* attribute, - const bool& required, const std::string& defaultValue, const std::string& exception = std::string("")); + const bool& required, const std::string& defaultValue, const std::string& exception = std::string("")); int readIntegerProp(xmlNodePtr node, const xmlChar* attribute, - const bool& required, const int& defaultValue, const std::string& exception = std::string("")); + const bool& required, const int& defaultValue, const std::string& exception = std::string("")); std::string readStringProp(xmlNodePtr node, const xmlChar* attribute, - const bool& required, const std::string& defaultValue, - const std::string& exception /*= std::string() */) + const bool& required, const std::string& defaultValue, + const std::string& exception /*= std::string() */) { xmlChar* strAttr = xmlGetProp(node, attribute); if (strAttr == NULL) @@ -138,8 +138,8 @@ namespace { } int readIntegerProp(xmlNodePtr node, const xmlChar* attribute, - const bool& required, const int& defaultValue, - const std::string& exception /*= std::string() */) + const bool& required, const int& defaultValue, + const std::string& exception /*= std::string() */) { xmlChar* strAttr = xmlGetProp(node, attribute); if (strAttr == NULL) @@ -183,7 +183,7 @@ namespace { } void exportGeometricElements(Geometry* xaoGeometry, - xmlNodePtr topology, XAO::Dimension dim, const xmlChar* colTag, const xmlChar* eltTag) + xmlNodePtr topology, XAO::Dimension dim, const xmlChar* colTag, const xmlChar* eltTag) { xmlNodePtr vertices = xmlNewChild(topology, 0, colTag, 0); xmlNewProp(vertices, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(xaoGeometry->countElements(dim)).c_str()); @@ -592,12 +592,16 @@ namespace { int component = readIntegerProp(valNode, C_ATTR_VALUE_COMPONENT, true, -1); xmlChar* data = xmlNodeGetContent(valNode->children); - if (data == NULL) + std::string value = (char*)data; + if (data != NULL) + { + value = (char*)data; + } + else if (step->getType() != XAO::STRING) { throw XAO_Exception(MsgBuilder() << "Line " << valNode->line << ": no content for value."); } - std::string value = (char*)data; step->setStringValue(index, component, value); } }