From 37b0d2eb734d5f2e4b8cffb56fe27d3dafcaf9cd Mon Sep 17 00:00:00 2001 From: fps Date: Tue, 9 Apr 2013 12:00:09 +0000 Subject: [PATCH] import/export XAO for topology and groups + rework --- configure.ac | 11 +- src/GEOMGUI/GEOM_msg_en.ts | 12 +- .../GEOMImpl_IImportExportOperations.cxx | 384 +++++++------ .../GEOMImpl_IImportExportOperations.hxx | 52 +- src/GEOMImpl/Makefile.am | 5 +- src/ImportExportGUI/ImportExportGUI.cxx | 49 +- src/ImportExportGUI/ImportExportGUI.h | 12 +- .../ImportExportGUI_ExportXAODlg.cxx | 280 ++++----- .../ImportExportGUI_ExportXAODlg.h | 63 +-- src/XAO/Field.cxx | 2 +- src/XAO/Field.hxx | 6 +- src/XAO/GeometricElement.cxx | 105 ++++ src/XAO/GeometricElement.hxx | 85 +++ src/XAO/Geometry.cxx | 284 ++++------ src/XAO/Geometry.hxx | 140 +++-- src/XAO/Group.cxx | 9 +- src/XAO/Group.hxx | 77 ++- src/XAO/Makefile.am | 41 +- src/XAO/Xao.cxx | 532 ++++++++++++++++-- src/XAO/Xao.hxx | 75 ++- src/XAO/XaoUtils.cxx | 61 ++ src/XAO/XaoUtils.hxx | 37 ++ src/XAO/tests/ImportExportTest.cxx | 167 ++++++ src/XAO/tests/ImportExportTest.hxx | 31 + src/XAO/tests/MainTest.hxx | 161 ++++++ src/XAO/tests/Makefile.am | 32 ++ src/XAO/tests/XAOTests.cxx | 5 + src/XAO/tests/data/test.xao | 321 +++++++++++ 28 files changed, 2293 insertions(+), 746 deletions(-) create mode 100644 src/XAO/GeometricElement.cxx create mode 100644 src/XAO/GeometricElement.hxx create mode 100644 src/XAO/XaoUtils.cxx create mode 100644 src/XAO/XaoUtils.hxx create mode 100644 src/XAO/tests/ImportExportTest.cxx create mode 100644 src/XAO/tests/ImportExportTest.hxx create mode 100644 src/XAO/tests/MainTest.hxx create mode 100755 src/XAO/tests/Makefile.am create mode 100644 src/XAO/tests/XAOTests.cxx create mode 100644 src/XAO/tests/data/test.xao diff --git a/configure.ac b/configure.ac index 1605a48f0..13db63495 100644 --- a/configure.ac +++ b/configure.ac @@ -359,6 +359,14 @@ echo CHECK_KERNEL +echo +echo --------------------------------------------- +echo Testing cppunit +echo --------------------------------------------- +echo + +CHECK_CPPUNIT + echo echo --------------------------------------------- echo Summary @@ -373,7 +381,7 @@ fi echo obligatory_vars="cc_ok lex_yacc_ok python_ok swig_ok threads_ok vtk_ok hdf5_ok omniORB_ok boost_ok libxml_ok occ_ok doxygen_ok graphviz_ok sphinx_ok Kernel_ok" -optional_vars="opencv_ok" +optional_vars="opencv_ok cppunit_ok" gui_vars="OpenGL_ok qt_ok gui_ok" ### @@ -496,6 +504,7 @@ AC_OUTPUT([ \ src/Makefile \ src/AdvancedGUI/Makefile \ src/XAO/Makefile \ + src/XAO/tests/Makefile \ src/ImportExportGUI/Makefile \ src/ARCHIMEDE/Makefile \ src/BREPExport/Makefile \ diff --git a/src/GEOMGUI/GEOM_msg_en.ts b/src/GEOMGUI/GEOM_msg_en.ts index e741c1392..658891901 100644 --- a/src/GEOMGUI/GEOM_msg_en.ts +++ b/src/GEOMGUI/GEOM_msg_en.ts @@ -5762,21 +5762,25 @@ Do you want to create new material? @default + + MEN_IMPORTEXPORT + Import / Export + TOP_EXPORTXAO - ExportXAO + Export to XAO MEN_EXPORTXAO - ExportXAO + Export XAO STB_EXPORTXAO - ExportXAO + Export shape to XAO format GEOM_IMPORTEXPORT_204 - ExportXAO + Export XAO diff --git a/src/GEOMImpl/GEOMImpl_IImportExportOperations.cxx b/src/GEOMImpl/GEOMImpl_IImportExportOperations.cxx index ceba312da..36bf1f3b7 100644 --- a/src/GEOMImpl/GEOMImpl_IImportExportOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IImportExportOperations.cxx @@ -19,6 +19,10 @@ // File : GEOMImpl_IImportExportOperations.cxx // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) +#include +#include +#include + #include #include "GEOMImpl_Types.hxx" @@ -46,6 +50,7 @@ #include "Xao.hxx" #include "Geometry.hxx" #include "Group.hxx" +#include "XaoUtils.hxx" #include #include @@ -68,7 +73,9 @@ #include #include #include -#include +#include +#include + #include #include @@ -76,26 +83,25 @@ #include #include #include // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC - //============================================================================= /*! * Constructor */ //============================================================================= -GEOMImpl_IImportExportOperations::GEOMImpl_IImportExportOperations(GEOM_Engine* theEngine, int theDocID) : - GEOM_IOperations(theEngine, theDocID) +GEOMImpl_IImportExportOperations::GEOMImpl_IImportExportOperations(GEOM_Engine* engine, int docID) : + GEOM_IOperations(engine, docID) { - MESSAGE("GEOMImpl_IImportExportOperations::GEOMImpl_IImportExportOperations"); - /*myBasicOperations = new GEOMImpl_IBasicOperations(GetEngine(), GetDocID()); - myBooleanOperations = new GEOMImpl_IBooleanOperations(GetEngine(), GetDocID()); - myShapesOperations = new GEOMImpl_IShapesOperations(GetEngine(), GetDocID()); - myTransformOperations = new GEOMImpl_ITransformOperations(GetEngine(), GetDocID()); - myBlocksOperations = new GEOMImpl_IBlocksOperations(GetEngine(), GetDocID()); - my3DPrimOperations = new GEOMImpl_I3DPrimOperations(GetEngine(), GetDocID()); - myLocalOperations = new GEOMImpl_ILocalOperations(GetEngine(), GetDocID()); - myHealingOperations = new GEOMImpl_IHealingOperations(GetEngine(), GetDocID());*/ - myShapesOperations = new GEOMImpl_IShapesOperations(GetEngine(), GetDocID()); - myGroupOperations = new GEOMImpl_IGroupOperations(GetEngine(), GetDocID()); + MESSAGE("GEOMImpl_IImportExportOperations::GEOMImpl_IImportExportOperations"); + /*myBasicOperations = new GEOMImpl_IBasicOperations(GetEngine(), GetDocID()); + myBooleanOperations = new GEOMImpl_IBooleanOperations(GetEngine(), GetDocID()); + myShapesOperations = new GEOMImpl_IShapesOperations(GetEngine(), GetDocID()); + myTransformOperations = new GEOMImpl_ITransformOperations(GetEngine(), GetDocID()); + myBlocksOperations = new GEOMImpl_IBlocksOperations(GetEngine(), GetDocID()); + my3DPrimOperations = new GEOMImpl_I3DPrimOperations(GetEngine(), GetDocID()); + myLocalOperations = new GEOMImpl_ILocalOperations(GetEngine(), GetDocID()); + myHealingOperations = new GEOMImpl_IHealingOperations(GetEngine(), GetDocID());*/ + m_shapesOperations = new GEOMImpl_IShapesOperations(GetEngine(), GetDocID()); + m_groupOperations = new GEOMImpl_IGroupOperations(GetEngine(), GetDocID()); } //============================================================================= @@ -105,160 +111,224 @@ GEOMImpl_IImportExportOperations::GEOMImpl_IImportExportOperations(GEOM_Engine* //============================================================================= GEOMImpl_IImportExportOperations::~GEOMImpl_IImportExportOperations() { - MESSAGE("GEOMImpl_IImportExportOperations::~GEOMImpl_IImportExportOperations"); - /*delete myBasicOperations; - delete myBooleanOperations; - delete myShapesOperations; - delete myTransformOperations; - delete myBlocksOperations; - delete my3DPrimOperations; - delete myLocalOperations; - delete myHealingOperations;*/ - delete myShapesOperations; - delete myGroupOperations; + MESSAGE("GEOMImpl_IImportExportOperations::~GEOMImpl_IImportExportOperations"); + /*delete myBasicOperations; + delete myBooleanOperations; + delete myShapesOperations; + delete myTransformOperations; + delete myBlocksOperations; + delete my3DPrimOperations; + delete myLocalOperations; + delete myHealingOperations;*/ + delete m_shapesOperations; + delete m_groupOperations; } //============================================================================= /*! * Export a shape to XAO Format - * \param theExportingShape Shape to export - * \param theFileName The name of the exported file - * \param thelGroups List of groups to export - * \param thelFields List of fields to export + * \param shape The shape to export + * \param fileName The name of the exported file + * \param groupList The list of groups to export + * \param fieldList The list of fields to export * \return New GEOM_Object, containing the created shape. */ //============================================================================= -bool GEOMImpl_IImportExportOperations::ExportXAO (Handle(GEOM_Object) theExportingShape, const std::string theFileName, std::list thelGroups, std::list thelFields) +bool GEOMImpl_IImportExportOperations::ExportXAO(Handle(GEOM_Object) shape, + const std::string fileName, + std::list groupList, + std::list fieldList) { - SetErrorCode(KO); - bool isGood = false; - - // - - //Add a new shape function with parameters - Handle(GEOM_Function) aRefFunction = theExportingShape->GetLastFunction(); - if (aRefFunction.IsNull()) return false; - - //Add a new result object - Handle(GEOM_Object) result = GetEngine()->AddObject(GetDocID(), GEOM_IMPORT); - - //Add an Export function - Handle(GEOM_Function) aFunction = result->AddFunction(GEOMImpl_ExportXAODriver::GetID(), EXPORTXAO_EXPORTINGSHAPE_FILENAME_LGROUPS_LFIELDS); - if (aFunction.IsNull()) return false; - - //Check if the function is set correctly - if (aFunction->GetDriverGUID() != GEOMImpl_ExportXAODriver::GetID()) return false; - - /*GEOMImpl_IExportXAO aData (aRefFunction); - - TCollection_AsciiString FileName = theFileName.c_str(); - aData.SetExportingShape(aRefFunction); - aData.SetFileName(FileName); - aData.SetlGroups(thelGroups); - aData.SetlFields(thelFields); - - //Compute the resulting value - try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 - OCC_CATCH_SIGNALS; -#endif - if (!GetSolver()->ComputeFunction(aFunction)) { - SetErrorCode("ExportXAO driver failed : Not enough space on disk, or you haven't permissions to write this directory"); - return false; + std::cout << ">> ExportXAO" << std::endl; + SetErrorCode(KO); + bool isGood = false; + + // + + // add a new shape function with parameters + Handle(GEOM_Function) lastFunction = shape->GetLastFunction(); + if (lastFunction.IsNull()) + return false; + + // add a new result object + Handle(GEOM_Object) result = GetEngine()->AddObject(GetDocID(), GEOM_IMPORT); + + // add an Export function + Handle(GEOM_Function) exportFunction = result->AddFunction(GEOMImpl_ExportXAODriver::GetID(), + EXPORTXAO_EXPORTINGSHAPE_FILENAME_LGROUPS_LFIELDS); + if (exportFunction.IsNull()) + return false; + + // check if the function is set correctly + if (exportFunction->GetDriverGUID() != GEOMImpl_ExportXAODriver::GetID()) + return false; + + /*GEOMImpl_IExportXAO aData (aRefFunction); + + TCollection_AsciiString FileName = theFileName.c_str(); + aData.SetExportingShape(aRefFunction); + aData.SetFileName(FileName); + aData.SetlGroups(thelGroups); + aData.SetlFields(thelFields); + + //Compute the resulting value + try { + #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 + OCC_CATCH_SIGNALS; + #endif + if (!GetSolver()->ComputeFunction(aFunction)) { + SetErrorCode("ExportXAO driver failed : Not enough space on disk, or you haven't permissions to write this directory"); + return false; + } + } + catch (Standard_Failure) { + Handle(Standard_Failure) aFail = Standard_Failure::Caught(); + SetErrorCode(aFail->GetMessageString()); + return false; + }*/ + XAO::Xao* xaoObject = new XAO::Xao(); + + XAO::Geometry* geometry = new XAO::Geometry(); + TopoDS_Shape topoShape = shape->GetValue(); + std::ostringstream dumpStream; + BRepTools::Dump(topoShape, dumpStream); + geometry->setShape(dumpStream.str().c_str()); + geometry->setName(shape->GetName()); + + Handle(TColStd_HSequenceOfTransient) subObjects = m_shapesOperations->GetExistingSubObjects(shape, false); + int nbSubObjects = subObjects->Length(); + std::cout << "nb sub obj = " << nbSubObjects << std::endl; + int nbVertices = 0, nbEdges = 0, nbFaces = 0, nbSolids = 0, nbGroups = 0; + for (int i = 1; i <= nbSubObjects; i++) + { + Handle(Standard_Transient) transientSubObject = subObjects->Value(i); + if (transientSubObject.IsNull()) + continue; + + Handle(GEOM_Object) subObject = Handle(GEOM_Object)::DownCast(transientSubObject); + if (subObject->GetType() == GEOM_GROUP) + { + nbGroups++; + } + else + { + switch (subObject->GetValue().ShapeType()) + { + case TopAbs_VERTEX: nbVertices++; break; + case TopAbs_EDGE: nbEdges++; break; + case TopAbs_FACE: nbFaces++; break; + case TopAbs_SOLID: nbSolids++; break; + } + } } - } - catch (Standard_Failure) { - Handle(Standard_Failure) aFail = Standard_Failure::Caught(); - SetErrorCode(aFail->GetMessageString()); - return false; - }*/ - TCollection_AsciiString FileName = theFileName.c_str(); - XAO::Xao *myXao = new XAO::Xao(); - XAO::Geometry *myGeometry = new XAO::Geometry(); - myGeometry->setShape(theExportingShape->GetValue()); - myGeometry->setName(theExportingShape->GetName()); - Handle(TColStd_HSequenceOfTransient) subObjects = myShapesOperations->GetExistingSubObjects(theExportingShape, false); - int nbSubObjects = subObjects->Length(); - for (int i = 1 ; i <= nbSubObjects ; i++) { - Handle(Standard_Transient) anTransientSubObject = subObjects->Value(i); - if (anTransientSubObject.IsNull()) - continue; - Handle(GEOM_Object) asubObject = Handle(GEOM_Object)::DownCast(anTransientSubObject); - if (asubObject->GetType() != GEOM_GROUP) + + std::cout << "Nb = " << nbVertices << ", " << nbEdges << ", " << nbFaces << ", " << nbSolids << ", " << nbGroups << std::endl; + if (nbVertices > 0) geometry->setCountVertices(nbVertices); + if (nbEdges > 0) geometry->setCountEdges(nbEdges); + if (nbFaces > 0) geometry->setCountFaces(nbFaces); + if (nbSolids > 0) geometry->setCountSolids(nbSolids); + + int vInd = 0, eInd = 0, fInd = 0, sInd = 0; + for (int i = 1; i <= nbSubObjects; i++) { - int index = myShapesOperations->GetSubShapeIndex(theExportingShape,asubObject); - switch (asubObject->GetValue().ShapeType() ) - { - case TopAbs_SOLID: - break; - case TopAbs_FACE: - break; - case TopAbs_EDGE: - break; - case TopAbs_VERTEX: - myGeometry->setVertexName(index,asubObject->GetName()); - break; - } - } - } - myXao->setGeometry(myGeometry); - - // Adding groups - std::list::iterator itG1 = thelGroups.begin(); - while (itG1 != thelGroups.end()) { - Handle(GEOM_Object) itGroup = (*itG1++); - XAO::Group *Group = new XAO::Group(); - Group->setName(itGroup->GetName()); - Handle(TColStd_HArray1OfInteger) groupIds = myGroupOperations->GetObjects(itGroup); - TopAbs_ShapeEnum shapeGroup = myGroupOperations->GetType(itGroup); - if (shapeGroup == TopAbs_VERTEX) + Handle(Standard_Transient) transientSubObject = subObjects->Value(i); + if (transientSubObject.IsNull()) + continue; + + Handle(GEOM_Object) subObject = Handle(GEOM_Object)::DownCast(transientSubObject); + std::cout << " sub[" << i << "] N=" << subObject->GetName() + //<< " E=" << subObject->GetEntry() + //<< " D=" << subObject->GetDocID() + << " T=" << subObject->GetType() << std::endl; + if (subObject->GetType() != GEOM_GROUP) + { + int index = m_shapesOperations->GetSubShapeIndex(shape, subObject); + const char* strIndex = XAO::XaoUtils::intToString(index); + std::cout << " index= " << index << std::endl; + switch (subObject->GetValue().ShapeType()) + { + case TopAbs_VERTEX: + geometry->setVertex(vInd++, subObject->GetName(), strIndex); + break; + case TopAbs_EDGE: + geometry->setEdge(eInd++, subObject->GetName(), strIndex); + break; + case TopAbs_FACE: + geometry->setFace(fInd++, subObject->GetName(), strIndex); + break; + case TopAbs_SOLID: + geometry->setSolid(sInd++, subObject->GetName(), strIndex); + break; + } + } + } + xaoObject->setGeometry(geometry); + + xaoObject->exportToFile(fileName.c_str()); + + /* + // adding groups + std::list::iterator itG1 = groupList.begin(); + int gInd = 0; + while (itG1 != groupList.end()) { - Group->setType(0); - for (int i = 1; i <= groupIds->Length(); i++) - { - int index = myGeometry->findVertex(groupIds->Value(i)); - Group->addValue(index); - } + std::cout << "Group = " << gInd++ << std::endl; + Handle(GEOM_Object) itGroup = (*itG1++); + XAO::Group* group = new XAO::Group(); + group->setName(itGroup->GetName()); + Handle(TColStd_HArray1OfInteger) groupIds = m_groupOperations->GetObjects(itGroup); + TopAbs_ShapeEnum shapeGroup = m_groupOperations->GetType(itGroup); + std::cout << "GroupShape = " << shapeGroup << std::endl; + if (shapeGroup == TopAbs_VERTEX) + { + group->setDimension(0); + for (int i = 1; i <= groupIds->Length(); i++) + { + const char* index = geometry->getVertexReference(groupIds->Value(i)); + group->addElement(index); + } + } + xaoObject->addGroup(group); + /*{ + case TopAbs_SOLID: + Group->setType(3); + break; + case TopAbs_FACE: + Group->setType(2); + break; + case TopAbs_EDGE: + Group->setType(1); + break; + case TopAbs_VERTEX: + Group->setType(0); + break; + } * + + }*/ + + /* + // make a Python command + TCollection_AsciiString fileNameStr = fileName.c_str(); + GEOM::TPythonDump pd(exportFunction); + std::list::iterator itG = groupList.begin(); + std::list::iterator itF = fieldList.begin(); + //pd << /*isGood <<**" = geompy.ExportXAO(" << shape << ", " << fileNameStr.ToCString() << ", ["; + + pd << (*itG++); + while (itG != groupList.end()) + { + pd << ", " << (*itG++); } - myXao->addGroup(Group); - /*{ - case TopAbs_SOLID: - Group->setType(3); - break; - case TopAbs_FACE: - Group->setType(2); - break; - case TopAbs_EDGE: - Group->setType(1); - break; - case TopAbs_VERTEX: - Group->setType(0); - break; - } */ - - - } - - - //Make a Python command - GEOM::TPythonDump pd (aFunction); - std::list::iterator itG = thelGroups.begin(); - std::list::iterator itF = thelFields.begin(); - pd << /*isGood <<*/ " = geompy.ExportXAO(" << theExportingShape << ", " << FileName.ToCString() << ", ["; - - pd << (*itG++); - while (itG != thelGroups.end()) { - pd << ", " << (*itG++); - } - pd << "], ["; - pd << (*itF++); - while (itF != thelFields.end()) { - pd << ", " << (*itF++); - } - pd << "])"; - - SetErrorCode(OK); - - return isGood; + pd << "], ["; + pd << (*itF++); + while (itF != fieldList.end()) + { + pd << ", " << (*itF++); + } + pd << "])";*/ + + SetErrorCode(OK); + + return isGood; } /*@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@*/ diff --git a/src/GEOMImpl/GEOMImpl_IImportExportOperations.hxx b/src/GEOMImpl/GEOMImpl_IImportExportOperations.hxx index e4b1ffc0a..6167f3571 100644 --- a/src/GEOMImpl/GEOMImpl_IImportExportOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_IImportExportOperations.hxx @@ -30,35 +30,39 @@ #include /*class GEOMImpl_IBasicOperations; -class GEOMImpl_IBooleanOperations; -class GEOMImpl_IShapesOperations; -class GEOMImpl_ITransformOperations; -class GEOMImpl_IBlocksOperations; -class GEOMImpl_I3DPrimOperations; -class GEOMImpl_ILocalOperations; -class GEOMImpl_IHealingOperations;*/ + class GEOMImpl_IBooleanOperations; + class GEOMImpl_IShapesOperations; + class GEOMImpl_ITransformOperations; + class GEOMImpl_IBlocksOperations; + class GEOMImpl_I3DPrimOperations; + class GEOMImpl_ILocalOperations; + class GEOMImpl_IHealingOperations;*/ class GEOMImpl_IShapesOperations; class GEOMImpl_IGroupOperations; -class GEOMImpl_IImportExportOperations: public GEOM_IOperations { +class GEOMImpl_IImportExportOperations: public GEOM_IOperations +{ private: - /*GEOMImpl_IBasicOperations* myBasicOperations; - GEOMImpl_IBooleanOperations* myBooleanOperations; - GEOMImpl_IShapesOperations* myShapesOperations; - GEOMImpl_ITransformOperations* myTransformOperations; - GEOMImpl_IBlocksOperations* myBlocksOperations; - GEOMImpl_I3DPrimOperations* my3DPrimOperations; - GEOMImpl_ILocalOperations* myLocalOperations; - GEOMImpl_IHealingOperations* myHealingOperations;*/ - GEOMImpl_IShapesOperations* myShapesOperations; - GEOMImpl_IGroupOperations* myGroupOperations; - + /*GEOMImpl_IBasicOperations* myBasicOperations; + GEOMImpl_IBooleanOperations* myBooleanOperations; + GEOMImpl_IShapesOperations* myShapesOperations; + GEOMImpl_ITransformOperations* myTransformOperations; + GEOMImpl_IBlocksOperations* myBlocksOperations; + GEOMImpl_I3DPrimOperations* my3DPrimOperations; + GEOMImpl_ILocalOperations* myLocalOperations; + GEOMImpl_IHealingOperations* myHealingOperations;*/ + GEOMImpl_IShapesOperations* m_shapesOperations; + GEOMImpl_IGroupOperations* m_groupOperations; + public: - Standard_EXPORT GEOMImpl_IImportExportOperations(GEOM_Engine* theEngine, int theDocID); - Standard_EXPORT ~GEOMImpl_IImportExportOperations(); - - Standard_EXPORT bool ExportXAO (Handle(GEOM_Object) theExportingShape, const std::string theFileName, std::list thelGroups, std::list thelFields); - /*@@ insert new functions before this line @@ do not remove this line @@*/ + Standard_EXPORT GEOMImpl_IImportExportOperations(GEOM_Engine* engine, int docID); + Standard_EXPORT ~GEOMImpl_IImportExportOperations(); + + Standard_EXPORT bool ExportXAO (Handle(GEOM_Object) shape, + const std::string fileName, + std::list groupList, + std::list fieldList); + /*@@ insert new functions before this line @@ do not remove this line @@*/ }; #endif diff --git a/src/GEOMImpl/Makefile.am b/src/GEOMImpl/Makefile.am index 4d0821d97..599b0bf07 100644 --- a/src/GEOMImpl/Makefile.am +++ b/src/GEOMImpl/Makefile.am @@ -237,11 +237,12 @@ dist_libGEOMimpl_la_SOURCES += $(IMPORTEXPORT_SOURCES) libGEOMimpl_la_CPPFLAGS = \ $(CORBA_CXXFLAGS) \ - $(CORBA_INCLUDES) \ + $(CORBA_INCLUDES) \ $(CAS_CPPFLAGS) \ $(KERNEL_CXXFLAGS) \ $(BOOST_CPPFLAGS) \ - $(PYTHON_INCLUDES) \ + $(PYTHON_INCLUDES) \ + $(LIBXML_INCLUDES) \ -I$(srcdir)/../ShHealOper \ -I$(srcdir)/../NMTDS \ -I$(srcdir)/../NMTTools \ diff --git a/src/ImportExportGUI/ImportExportGUI.cxx b/src/ImportExportGUI/ImportExportGUI.cxx index 7b9f7adb2..05eba148b 100644 --- a/src/ImportExportGUI/ImportExportGUI.cxx +++ b/src/ImportExportGUI/ImportExportGUI.cxx @@ -41,7 +41,8 @@ // function : ImportExportGUI() // purpose : Constructor //======================================================================= -ImportExportGUI::ImportExportGUI( GeometryGUI* parent ) : GEOMGUI( parent ) +ImportExportGUI::ImportExportGUI(GeometryGUI* parent) : + GEOMGUI(parent) { } @@ -57,30 +58,30 @@ ImportExportGUI::~ImportExportGUI() // function : OnGUIEvent() // purpose : //======================================================================= -bool ImportExportGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent ) +bool ImportExportGUI::OnGUIEvent(int commandId, SUIT_Desktop* parent) { - SalomeApp_Application* app = getGeometryGUI()->getApp(); - if ( !app ) return false; + SalomeApp_Application* app = getGeometryGUI()->getApp(); + if (!app) return false; - getGeometryGUI()->EmitSignalDeactivateDialog(); + getGeometryGUI()->EmitSignalDeactivateDialog(); - QDialog* aDlg = NULL; - switch ( theCommandID ) { - case GEOMOp::OpExportXAO: - cout << "test" << endl; - aDlg = new ImportExportGUI_ExportXAODlg( getGeometryGUI(), parent ); - break; - //@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@// - default: - app->putInfo( tr( "GEOM_PRP_COMMAND" ).arg( theCommandID ) ); - break; - } + QDialog* dialog = NULL; + switch (commandId) + { + case GEOMOp::OpExportXAO: + dialog = new ImportExportGUI_ExportXAODlg(getGeometryGUI(), parent); + break; + //@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@// + default: + app->putInfo(tr("GEOM_PRP_COMMAND").arg(commandId)); + break; + } - if ( aDlg != NULL ) - aDlg->show(); + if (dialog != NULL) + dialog->show(); - return true; + return true; } //===================================================================================== @@ -89,10 +90,10 @@ bool ImportExportGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent ) extern "C" { #ifdef WIN32 - __declspec( dllexport ) + __declspec( dllexport ) #endif - GEOMGUI* GetLibGUI( GeometryGUI* parent ) - { - return new ImportExportGUI( parent ); - } + GEOMGUI* GetLibGUI(GeometryGUI* parent) + { + return new ImportExportGUI(parent); + } } diff --git a/src/ImportExportGUI/ImportExportGUI.h b/src/ImportExportGUI/ImportExportGUI.h index 261e1cacd..a2165bd9d 100644 --- a/src/ImportExportGUI/ImportExportGUI.h +++ b/src/ImportExportGUI/ImportExportGUI.h @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2013 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 @@ -24,18 +24,18 @@ #define IMPORTEXPORTGUI_H #include "GEOMGUI.h" - + //================================================================================= // class : ImportExportGUI // purpose : //================================================================================= -class ImportExportGUI : public GEOMGUI +class ImportExportGUI: public GEOMGUI { public: - ImportExportGUI( GeometryGUI* ); - ~ImportExportGUI(); + ImportExportGUI(GeometryGUI* parent); + ~ImportExportGUI(); - bool OnGUIEvent( int, SUIT_Desktop* ); + bool OnGUIEvent(int commandId, SUIT_Desktop* parent); }; #endif // IMPORTEXPORTGUI_H diff --git a/src/ImportExportGUI/ImportExportGUI_ExportXAODlg.cxx b/src/ImportExportGUI/ImportExportGUI_ExportXAODlg.cxx index 5216e1f8b..9fc2dc545 100644 --- a/src/ImportExportGUI/ImportExportGUI_ExportXAODlg.cxx +++ b/src/ImportExportGUI/ImportExportGUI_ExportXAODlg.cxx @@ -1,7 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// Copyright (C) 2013 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 @@ -19,9 +16,6 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -#include "ImportExportGUI_ExportXAODlg.h" -//#include "ImportExportGUI_Widgets.h" - #include #include #include @@ -47,84 +41,86 @@ #include #include +#include "ImportExportGUI_ExportXAODlg.h" +//#include "ImportExportGUI_Widgets.h" //================================================================================= // Constructor //================================================================================= -ImportExportGUI_ExportXAODlg::ImportExportGUI_ExportXAODlg (GeometryGUI* theGeometryGUI, QWidget* parent) - : GEOMBase_Skeleton(theGeometryGUI, parent, false) +ImportExportGUI_ExportXAODlg::ImportExportGUI_ExportXAODlg(GeometryGUI* geometryGUI, QWidget* parent) +: + GEOMBase_Skeleton(geometryGUI, parent, false) { - myMainObj = GEOM::GEOM_Object::_nil(); - - SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); - QPixmap imageOp (resMgr->loadPixmap("GEOM", tr("ICON_DLG_EXPORTXAO_EXPORTINGSHAPE_FILENAME_LGROUPS_LFIELDS"))); - QPixmap iconSelect (resMgr->loadPixmap("GEOM", tr("ICON_SELECT"))); - - setWindowTitle(tr("GEOM_EXPORTXAO_TITLE")); - - /***************************************************************/ - mainFrame()->GroupConstructors->setTitle( tr( "GEOM_EXPORTXAO_TITLE" ) ); - mainFrame()->RadioButton1->setIcon( imageOp ); - mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose ); - mainFrame()->RadioButton2->close(); - mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose ); - mainFrame()->RadioButton3->close(); - - - QGroupBox *GroupBoxExport = new QGroupBox(parent); - - QGridLayout *gridLayoutExport = new QGridLayout(GroupBoxExport); + m_mainObj = GEOM::GEOM_Object::_nil(); + + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + QPixmap imageOp(resMgr->loadPixmap("GEOM", tr("ICON_DLG_EXPORTXAO_EXPORTINGSHAPE_FILENAME_LGROUPS_LFIELDS"))); + QPixmap iconSelect(resMgr->loadPixmap("GEOM", tr("ICON_SELECT"))); + + setWindowTitle(tr("GEOM_EXPORTXAO_TITLE")); + + /***************************************************************/ + mainFrame()->GroupConstructors->setTitle(tr("GEOM_EXPORTXAO_TITLE")); + mainFrame()->RadioButton1->setIcon(imageOp); + mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose); + mainFrame()->RadioButton2->close(); + mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose); + mainFrame()->RadioButton3->close(); + + QGroupBox* gbxExport = new QGroupBox(parent); + + QGridLayout *gridLayoutExport = new QGridLayout(gbxExport); #ifndef Q_OS_MAC - gridLayoutExport->setSpacing(6); + gridLayoutExport->setSpacing(6); #endif #ifndef Q_OS_MAC - gridLayoutExport->setContentsMargins(9, 9, 9, 9); + gridLayoutExport->setContentsMargins(9, 9, 9, 9); #endif - gridLayoutExport->setObjectName(QString::fromUtf8("gridLayoutExport")); + gridLayoutExport->setObjectName(QString::fromUtf8("gridLayoutExport")); + + //**************************** + QLabel* txtLabel1 = new QLabel(tr("GEOM_EXPORTXAO_EXPORTINGSHAPE"), gbxExport); + gridLayoutExport->addWidget(txtLabel1, 0, 0, 1, 1); - //**************************** - QLabel *TextLabel1 = new QLabel(tr( "GEOM_EXPORTXAO_EXPORTINGSHAPE" ),GroupBoxExport); - gridLayoutExport->addWidget(TextLabel1, 0, 0, 1, 1); + btnSelect = new QPushButton(gbxExport); + btnSelect->setIcon(iconSelect); + gridLayoutExport->addWidget(btnSelect, 0, 1, 1, 1); - mySelBtn = new QPushButton(GroupBoxExport); - mySelBtn->setIcon(iconSelect); - gridLayoutExport->addWidget(mySelBtn, 0, 1, 1, 1); + ledShape = new QLineEdit(gbxExport); + ledShape->setMinimumSize(QSize(100, 0)); + gridLayoutExport->addWidget(ledShape, 0, 2, 1, 1); - myMainShape = new QLineEdit(GroupBoxExport); - myMainShape->setMinimumSize(QSize(100, 0)); - gridLayoutExport->addWidget(myMainShape, 0, 2, 1, 1); + //**************************** + QLabel* txtLabel2 = new QLabel(tr("GEOM_EXPORTXAO_FILENAME"), gbxExport); + gridLayoutExport->addWidget(txtLabel2, 1, 0, 1, 1); - //**************************** - QLabel *TextLabel2 = new QLabel(tr( "GEOM_EXPORTXAO_FILENAME" ),GroupBoxExport); - gridLayoutExport->addWidget(TextLabel2, 1, 0, 1, 1); + ledFileName = new QLineEdit(gbxExport); + gridLayoutExport->addWidget(ledFileName, 1, 1, 1, 2); - myMainFile = new QLineEdit(GroupBoxExport); - gridLayoutExport->addWidget(myMainFile, 1, 1, 1, 2); + //**************************** + QLabel* txtLabel3 = new QLabel(tr("GEOM_EXPORTXAO_LGROUPS"), gbxExport); + gridLayoutExport->addWidget(txtLabel3, 2, 0, 1, 2); - //**************************** - QLabel *TextLabel3 = new QLabel(tr( "GEOM_EXPORTXAO_LGROUPS" ),GroupBoxExport); - gridLayoutExport->addWidget(TextLabel3, 2, 0, 1, 2); - - myListGroups = new QListWidget(GroupBoxExport); - gridLayoutExport->addWidget(myListGroups, 3, 0, 1, 2); + lstGroups = new QListWidget(gbxExport); + gridLayoutExport->addWidget(lstGroups, 3, 0, 1, 2); - QLabel *TextLabel4 = new QLabel(tr( "GEOM_EXPORTXAO_LFIELDS" ),GroupBoxExport); - gridLayoutExport->addWidget(TextLabel4, 2, 2, 1, 1); + QLabel* txtLabel4 = new QLabel(tr("GEOM_EXPORTXAO_LFIELDS"), gbxExport); + gridLayoutExport->addWidget(txtLabel4, 2, 2, 1, 1); - myListFields = new QListWidget(GroupBoxExport); - gridLayoutExport->addWidget(myListFields, 3, 2, 1, 1); + lstFields = new QListWidget(gbxExport); + gridLayoutExport->addWidget(lstFields, 3, 2, 1, 1); + QVBoxLayout* layout = new QVBoxLayout(centralWidget()); + layout->setMargin(0); + layout->setSpacing(6); + layout->addWidget(gbxExport); - QVBoxLayout* layout = new QVBoxLayout(centralWidget()); - layout->setMargin(0); layout->setSpacing(6); - layout->addWidget(GroupBoxExport); + //QWidget::setTabOrder(PushButton1, LineEdit1); + //QWidget::setTabOrder(LineEdit1, LineEdit2); - //QWidget::setTabOrder(PushButton1, LineEdit1); - //QWidget::setTabOrder(LineEdit1, LineEdit2); - - setHelpFileName("create_exportxao_page.html"); + setHelpFileName("create_exportxao_page.html"); - Init(); + Init(); } //================================================================================= @@ -132,7 +128,7 @@ ImportExportGUI_ExportXAODlg::ImportExportGUI_ExportXAODlg (GeometryGUI* theGeom //================================================================================= ImportExportGUI_ExportXAODlg::~ImportExportGUI_ExportXAODlg() { - // no need to delete child widgets, Qt does it all for us + // no need to delete child widgets, Qt does it all for us } //================================================================================= @@ -141,20 +137,20 @@ ImportExportGUI_ExportXAODlg::~ImportExportGUI_ExportXAODlg() //================================================================================= void ImportExportGUI_ExportXAODlg::Init() { - // Get setting of step value from file configuration - myGroups.clear(); - myFields.clear(); + // Get setting of step value from file configuration + m_groups.clear(); + m_fields.clear(); - // Signal/slot connections - connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk())); - connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply())); + // Signal/slot connections + connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk())); + connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply())); - connect( mySelBtn, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); - connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), - SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); + connect(btnSelect, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + connect(((SalomeApp_Application*) (SUIT_Session::session()->activeApplication()))->selectionMgr(), + SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())); - initName(tr("GEOM_EXPORTXAO")); - SelectionIntoArgument(); + initName(tr("GEOM_EXPORTXAO")); + SelectionIntoArgument(); } //================================================================================= @@ -163,20 +159,22 @@ void ImportExportGUI_ExportXAODlg::Init() //================================================================================= void ImportExportGUI_ExportXAODlg::processObject() { - if ( myMainObj->_is_nil() ) { - myMainShape->setText( "" ); - myMainFile->setText( "" ); - } - else { - myMainShape->setText( GEOMBase::GetName( myMainObj ) ); - GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations(getStudyId()); - GEOM::ListOfGO_var Groups = aShOp->GetExistingSubObjects(myMainObj, true); - // Affichage des noms des groupes - for ( int i = 0, n = Groups->length(); i < n; i++ ) + if (m_mainObj->_is_nil()) { - myListGroups->addItem( GEOMBase::GetName( Groups[i] ) ); + ledShape->setText(""); + ledFileName->setText(""); + } + else + { + ledShape->setText(GEOMBase::GetName(m_mainObj)); + GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations(getStudyId()); + GEOM::ListOfGO_var Groups = aShOp->GetExistingSubObjects(m_mainObj, true); + // Affichage des noms des groupes + for (int i = 0, n = Groups->length(); i < n; i++) + { + lstGroups->addItem(GEOMBase::GetName(Groups[i])); + } } - } } //================================================================================= @@ -185,8 +183,8 @@ void ImportExportGUI_ExportXAODlg::processObject() //================================================================================= void ImportExportGUI_ExportXAODlg::ClickOnOk() { - if (ClickOnApply()) - ClickOnCancel(); + if (ClickOnApply()) + ClickOnCancel(); } //================================================================================= @@ -195,12 +193,12 @@ void ImportExportGUI_ExportXAODlg::ClickOnOk() //================================================================================= bool ImportExportGUI_ExportXAODlg::ClickOnApply() { - if (!onAccept()) - return false; + if (!onAccept()) + return false; - initName(); + initName(); - return true; + return true; } //================================================================================= @@ -209,27 +207,27 @@ bool ImportExportGUI_ExportXAODlg::ClickOnApply() //================================================================================= void ImportExportGUI_ExportXAODlg::SelectionIntoArgument() { - myMainObj = GEOM::GEOM_Object::_nil(); + m_mainObj = GEOM::GEOM_Object::_nil(); - LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); - SALOME_ListIO aSelList; - aSelMgr->selectedObjects(aSelList); + LightApp_SelectionMgr* selMgr = myGeomGUI->getApp()->selectionMgr(); + SALOME_ListIO selList; + selMgr->selectedObjects(selList); - if (aSelList.Extent() != 1) { - processObject(); - return; - } + if (selList.Extent() != 1) + { + processObject(); + return; + } - /*GEOM::GEOM_Object_var aSelectedObject*/myMainObj = GEOMBase::ConvertIOinGEOMObject( aSelList.First() ); + /*GEOM::GEOM_Object_var aSelectedObject*/m_mainObj = GEOMBase::ConvertIOinGEOMObject(selList.First()); - /*if ( aSelectedObject->_is_nil() ) { - processObject(); - return; - }*/ + /*if ( aSelectedObject->_is_nil() ) { + processObject(); + return; + }*/ - //myMainObj = aSelectedObject; - - processObject(); + //myMainObj = aSelectedObject; + processObject(); } //================================================================================= @@ -238,9 +236,9 @@ void ImportExportGUI_ExportXAODlg::SelectionIntoArgument() //================================================================================= void ImportExportGUI_ExportXAODlg::SetEditCurrentArgument() { - myMainShape->setFocus(); - myEditCurrentArgument = myMainShape; - SelectionIntoArgument(); + ledShape->setFocus(); + myEditCurrentArgument = ledShape; + SelectionIntoArgument(); } //================================================================================= // function : ActivateThisDialog() @@ -248,17 +246,17 @@ void ImportExportGUI_ExportXAODlg::SetEditCurrentArgument() //================================================================================= void ImportExportGUI_ExportXAODlg::ActivateThisDialog() { - GEOMBase_Skeleton::ActivateThisDialog(); + GEOMBase_Skeleton::ActivateThisDialog(); } //================================================================================= // function : enterEvent [REDEFINED] // purpose : //================================================================================= -void ImportExportGUI_ExportXAODlg::enterEvent (QEvent*) +void ImportExportGUI_ExportXAODlg::enterEvent(QEvent*) { - if (!mainFrame()->GroupConstructors->isEnabled()) - ActivateThisDialog(); + if (!mainFrame()->GroupConstructors->isEnabled()) + ActivateThisDialog(); } //================================================================================= @@ -267,47 +265,51 @@ void ImportExportGUI_ExportXAODlg::enterEvent (QEvent*) //================================================================================= GEOM::GEOM_IOperations_ptr ImportExportGUI_ExportXAODlg::createOperation() { - return getGeomEngine()->GetIImportExportOperations(getStudyId()); + return getGeomEngine()->GetIImportExportOperations(getStudyId()); } //================================================================================= // function : isValid // purpose : //================================================================================= -bool ImportExportGUI_ExportXAODlg::isValid (QString& msg) +bool ImportExportGUI_ExportXAODlg::isValid(QString& msg) { - bool ok = true; + bool ok = true; - //@@ add custom validation actions here @@// + //@@ add custom validation actions here @@// - return ok; + return ok; } //================================================================================= // function : execute // purpose : //================================================================================= -bool ImportExportGUI_ExportXAODlg::execute (ObjectList& objects) +bool ImportExportGUI_ExportXAODlg::execute(ObjectList& objects) { - bool res = false; + bool res = false; + + GEOM::GEOM_Object_var obj; - GEOM::GEOM_Object_var anObj; + GEOM::GEOM_IImportExportOperations_var ieOp = GEOM::GEOM_IImportExportOperations::_narrow(getOperation()); + GEOM::GEOM_IShapesOperations_var shapesOp = getGeomEngine()->GetIShapesOperations(getStudyId()); + GEOM::ListOfGO_var groups = shapesOp->GetExistingSubObjects(m_mainObj, true); + GEOM::ListOfGO_var fields = new GEOM::ListOfGO(); - GEOM::GEOM_IImportExportOperations_var anOper = GEOM::GEOM_IImportExportOperations::_narrow(getOperation()); - GEOM::GEOM_IShapesOperations_var anShapesOper = getGeomEngine()->GetIShapesOperations(getStudyId()); - GEOM::ListOfGO_var mylGroups = anShapesOper->GetExistingSubObjects(myMainObj, true); - GEOM::ListOfGO_var mylFields = new GEOM::ListOfGO(); + std::cout << " == Groups" << std::endl; + groups->length(m_groups.count()); + for (int i = 0; i < m_groups.count(); i++) + groups[i] = m_groups[i].copy(); - mylGroups->length( myGroups.count() ); - for ( int i = 0; i < myGroups.count(); i++ ) - mylGroups[i] = myGroups[i].copy(); - - mylFields->length( myFields.count() ); - for ( int i = 0; i < myFields.count(); i++ ) - mylFields[i] = myFields[i].copy(); + std::cout << " == Fields" << std::endl; + fields->length(m_fields.count()); + for (int i = 0; i < m_fields.count(); i++) + fields[i] = m_fields[i].copy(); - // call engine function - res = anOper->ExportXAO(myMainObj, myMainFile->text().toStdString().c_str(), mylGroups, mylFields); + // call engine function + std::cout << " >> ExportXAO" << std::endl; + res = ieOp->ExportXAO(m_mainObj, ledFileName->text().toStdString().c_str(), groups, fields); + std::cout << " << ExportXAO" << std::endl; - return res; + return res; } diff --git a/src/ImportExportGUI/ImportExportGUI_ExportXAODlg.h b/src/ImportExportGUI/ImportExportGUI_ExportXAODlg.h index f89324ae7..825071e31 100644 --- a/src/ImportExportGUI/ImportExportGUI_ExportXAODlg.h +++ b/src/ImportExportGUI/ImportExportGUI_ExportXAODlg.h @@ -1,7 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// Copyright (C) 2013 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,7 +20,7 @@ #define IMPORTEXPORTGUI_EXPORTXAODLG_H #include -#include "GEOM_GenericObjPtr.h" +#include class QLineEdit; class QButtonGroup; @@ -35,45 +32,45 @@ class QListWidget; // class : ImportExportGUI_ExportXAODlg // purpose : //================================================================================= -class ImportExportGUI_ExportXAODlg : public GEOMBase_Skeleton +class ImportExportGUI_ExportXAODlg: public GEOMBase_Skeleton { - Q_OBJECT + Q_OBJECT public: - ImportExportGUI_ExportXAODlg( GeometryGUI*, QWidget* = 0 ); - ~ImportExportGUI_ExportXAODlg(); + ImportExportGUI_ExportXAODlg(GeometryGUI*, QWidget* = 0); + ~ImportExportGUI_ExportXAODlg(); protected: - // redefined from GEOMBase_Helper - virtual GEOM::GEOM_IOperations_ptr createOperation(); - virtual bool isValid( QString& ); - virtual bool execute( ObjectList& ); + // redefined from GEOMBase_Helper + virtual GEOM::GEOM_IOperations_ptr createOperation(); + virtual bool isValid(QString&); + virtual bool execute(ObjectList&); private: - void Init(); - void enterEvent( QEvent* ); - void processObject(); + void Init(); + void enterEvent(QEvent*); + void processObject(); private: - GEOM::GEOM_Object_var myMainObj; - QList myGroups; - QList myFields; - //ImportExportGUI_1Sel1LineEdit2ListWidget* myGrp; - QLineEdit *myMainShape; - QLineEdit *myMainFile; - QListWidget *myListGroups; - QListWidget *myListFields; - QPushButton *mySelBtn; + GEOM::GEOM_Object_var m_mainObj; + QList m_groups; + QList m_fields; + //ImportExportGUI_1Sel1LineEdit2ListWidget* myGrp; + QLineEdit* ledShape; + QLineEdit* ledFileName; + QListWidget* lstGroups; + QListWidget* lstFields; + QPushButton* btnSelect; private slots: - void ClickOnOk(); - bool ClickOnApply(); - void ActivateThisDialog(); - void LineEditReturnPressed(); - void SelectionIntoArgument(); - void SetEditCurrentArgument(); - //void ValueChangedInSpinBox(); - //void SetDoubleSpinBoxStep( double ); + void ClickOnOk(); + bool ClickOnApply(); + void ActivateThisDialog(); + void LineEditReturnPressed(); + void SelectionIntoArgument(); + void SetEditCurrentArgument(); + //void ValueChangedInSpinBox(); + //void SetDoubleSpinBoxStep( double ); }; #endif // IMPORTEXPORTGUI_EXPORTXAODLG_H diff --git a/src/XAO/Field.cxx b/src/XAO/Field.cxx index 173bb2db4..812ecf0d2 100644 --- a/src/XAO/Field.cxx +++ b/src/XAO/Field.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2012 CEA/DEN, EDF R&D +// Copyright (C) 2013 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public diff --git a/src/XAO/Field.hxx b/src/XAO/Field.hxx index c7352f465..5617f3e11 100644 --- a/src/XAO/Field.hxx +++ b/src/XAO/Field.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2012 CEA/DEN, EDF R&D +// Copyright (C) 2013 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -32,7 +32,7 @@ namespace XAO FACE = 2, SOLID = 3 } FieldDimension; - + typedef enum { BOOLEAN = 0, @@ -40,7 +40,7 @@ namespace XAO DOUBLE = 2, STRING = 3 } FieldType; - + class Field { public: diff --git a/src/XAO/GeometricElement.cxx b/src/XAO/GeometricElement.cxx new file mode 100644 index 000000000..4979b184b --- /dev/null +++ b/src/XAO/GeometricElement.cxx @@ -0,0 +1,105 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Frederic Pons (OpenCascade) + +#include + +#include "GeometricElement.hxx" + +using namespace XAO; + + +GeometricElement::GeometricElement() +{ + m_name = ""; + m_reference = ""; +} + +GeometricElement::GeometricElement(const char* name, const char* reference) +{ + m_name = name; + m_reference = reference; +} + +GeometricElement::~GeometricElement() +{ + +} + +GeometricElementList::GeometricElementList() +{ + setSize(0); +} + +GeometricElementList::GeometricElementList(const int count) +{ + setSize(m_count); +} + +void GeometricElementList::setSize(const int nb) +{ + m_count = nb; + m_elements.clear(); + for (int i = 0; i < nb; ++i) + { + m_elements[i] = GeometricElement(); + } +} + +void GeometricElementList::setElement(const int index, const char* name, const char* reference) +{ + if (m_count == 0 || index > m_count) + throw SALOME_Exception("Problem with number of elements"); + + m_elements[index].setName(name); + m_elements[index].setReference(reference); +} + + +const char* GeometricElementList::getName(const int index) +{ + if (m_count == 0 || index > m_count) + throw SALOME_Exception("Problem with number of elements"); + + return m_elements[index].getName(); +} + +void GeometricElementList::setName(const int index, const char* name) +{ + if (m_count == 0 || index > m_count) + throw SALOME_Exception("Problem with number of elements"); + + m_elements[index].setName(name); +} + +const char* GeometricElementList::getReference(const int index) +{ + if (m_count == 0 || index > m_count) + throw SALOME_Exception("Problem with number of elements"); + + return m_elements[index].getReference(); +} + +void GeometricElementList::setReference(const int index, const char* name) +{ + if (m_count == 0 || index > m_count) + throw SALOME_Exception("Problem with number of elements"); + + m_elements[index].setReference(name); +} diff --git a/src/XAO/GeometricElement.hxx b/src/XAO/GeometricElement.hxx new file mode 100644 index 000000000..3863b5849 --- /dev/null +++ b/src/XAO/GeometricElement.hxx @@ -0,0 +1,85 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Frederic Pons (OpenCascade) + +#ifndef __XAO_GEOMETRICELEMENT_HXX__ +#define __XAO_GEOMETRICELEMENT_HXX__ + +#include +#include + + + +namespace XAO +{ + class GeometricElement + { + public: + GeometricElement(); + GeometricElement(const char* name, const char* reference); + ~GeometricElement(); + + const char* getName() + { + return m_name.c_str(); + } + + void setName(const char* name) + { + m_name = name; + } + + const char* getReference() + { + return m_reference.c_str(); + } + + void setReference(const char* reference) + { + m_reference = reference; + } + + private: + std::string m_name; + std::string m_reference; + }; + + class GeometricElementList + { + public: + GeometricElementList(); + GeometricElementList(const int nb); + ~GeometricElementList() {} + + int getSize() { return m_count; } + void setSize(const int nb); + + void setElement(const int index, const char* name, const char* reference); + const char* getName(const int index); + void setName(const int index, const char* name); + const char* getReference(const int index); + void setReference(const int index, const char* reference); + + private: + int m_count; + std::map m_elements; + }; +} + +#endif /* __XAO_GEOMETRICELEMENT_HXX__ */ diff --git a/src/XAO/Geometry.cxx b/src/XAO/Geometry.cxx index 38d27d7bf..efade0422 100644 --- a/src/XAO/Geometry.cxx +++ b/src/XAO/Geometry.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2012 CEA/DEN, EDF R&D +// Copyright (C) 2013 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -18,6 +18,7 @@ // // Author : Nathalie Gore (OpenCascade) +#include "XaoUtils.hxx" #include "Geometry.hxx" #include @@ -29,7 +30,7 @@ #include #include #include -#include +#include #include #include @@ -41,210 +42,157 @@ #include #include #include - -using namespace std; using namespace XAO; Geometry::Geometry() { - _myFormat = "BREP"; - - _myNbVertices = 0; - _myNamesVertices = NULL; - _myIdsVertices = NULL; - - _myNbEdges = 0; - _myNamesEdges = NULL; - _myIdsEdges = NULL; - - _myNbFaces = 0; - _myNamesFaces = NULL; - _myIdsFaces = NULL; - - _myNbSolids = 0; - _myNamesSolids = NULL; - _myIdsSolids = NULL; + m_format = "BREP"; } Geometry::~Geometry() { - if (_myNamesVertices != NULL) - delete _myNamesVertices; - if (_myIdsVertices != NULL) - delete _myIdsVertices; - - if (_myNamesEdges != NULL) - delete _myNamesEdges; - if (_myIdsEdges != NULL) - delete _myIdsEdges; - - if (_myNamesFaces != NULL) - delete _myNamesFaces; - if (_myIdsFaces != NULL) - delete _myIdsFaces; - - if (_myNamesSolids != NULL) - delete _myNamesSolids; - if (_myIdsSolids != NULL) - delete _myIdsSolids; } -void Geometry::setShape(TopoDS_Shape Shape) +void Geometry::setShape(TopoDS_Shape shape) { - _myShape = Shape; - - // intialization of Ids - initListIds(TopAbs_VERTEX); - initListIds(TopAbs_EDGE); - initListIds(TopAbs_FACE); - initListIds(TopAbs_SOLID); + m_shape = shape; + + // intialization of Ids + initListIds(TopAbs_VERTEX); + initListIds(TopAbs_EDGE); + initListIds(TopAbs_FACE); + initListIds(TopAbs_SOLID); } -void Geometry::setShape(const char * brep ) +void Geometry::setShape(const char* brep) { - istringstream streamBrep(brep); - BRep_Builder aBuilder; - BRepTools::Read(_myShape, streamBrep, aBuilder); - - // intialization of Ids - initListIds(TopAbs_VERTEX); - initListIds(TopAbs_EDGE); - initListIds(TopAbs_FACE); - initListIds(TopAbs_SOLID); + std::istringstream streamBrep(brep); + BRep_Builder builder; + BRepTools::Read(m_shape, streamBrep, builder); + + // intialization of Ids + initListIds(TopAbs_VERTEX); + initListIds(TopAbs_EDGE); + initListIds(TopAbs_FACE); + initListIds(TopAbs_SOLID); } -const char * Geometry::getBREP() +const char* Geometry::getBREP() { - ostringstream streamShape; - BRepTools::Write(_myShape, streamShape); - return streamShape.str().c_str(); + std::ostringstream streamShape; + BRepTools::Write(m_shape, streamShape); + return streamShape.str().c_str(); } -void Geometry::setVertexName(int index, const char *myName) +/* +void Geometry::changeVertexName(int id, const char* name) { - if (_myNbVertices == 0 || index > _myNbVertices) - Standard_TypeMismatch::Raise("Problem with number of vertices"); + if (m_nbVertices == 0) + Standard_TypeMismatch::Raise("Problem with number of vertices"); - if (_myNamesVertices == NULL) - _myNamesVertices = new std::string[_myNbVertices]; - - _myNamesVertices[index] = myName; -} + if (m_verticesNames == NULL) + m_verticesNames = new std::string[m_nbVertices]; -void Geometry::changeVertexName(int id, const char *myName) -{ - if (_myNbVertices == 0) - Standard_TypeMismatch::Raise("Problem with number of vertices"); - - if (_myNamesVertices == NULL) - _myNamesVertices = new std::string[_myNbVertices]; - - int index = findVertex(id); - - if (index == -1) - Standard_TypeMismatch::Raise("Problem with the id of the vertex"); - - _myNamesVertices[index] = myName; + int index = findVertex(id); + + if (index == -1) + Standard_TypeMismatch::Raise("Problem with the id of the vertex"); + + m_verticesNames[index] = name; } -const char * Geometry::findVertexName(int id) +const char* Geometry::findVertexName(int id) { - if (_myNbVertices == 0) { - Standard_TypeMismatch::Raise("Problem with number of vertices"); - return ""; - } - - int index = findVertex(id); - - if (index == -1) { - Standard_TypeMismatch::Raise("Problem with the id of the vertex"); - return ""; - } - - return _myNamesVertices[index].c_str(); -} + if (m_nbVertices == 0) + { + Standard_TypeMismatch::Raise("Problem with number of vertices"); + return ""; + } + + int index = findVertex(id); + if (index == -1) + { + Standard_TypeMismatch::Raise("Problem with the id of the vertex"); + return ""; + } + + return m_verticesNames[index].c_str(); +}*/ +/* int Geometry::findVertex(int id) { - int index = -1; - for (int i = 0, n = _myNbVertices; i < n; i++) - { - if (_myIdsVertices[i] == id) - return i; - } - return index; -} + int index = -1; + for (int i = 0, n = m_nbVertices; i < n; i++) + { + if (m_verticesIds[i] == id) + return i; + } + return index; +}*/ -void Geometry::initListIds(const Standard_Integer theShapeType) +void Geometry::initListIds(const Standard_Integer shapeType) { - std::list aList; - - TopTools_MapOfShape mapShape; - TopTools_ListOfShape listShape; - - TopExp_Explorer exp (_myShape, TopAbs_ShapeEnum(theShapeType)); - for (; exp.More(); exp.Next()) - if (mapShape.Add(exp.Current())) - listShape.Append(exp.Current()); - - if (listShape.IsEmpty()) { - return ; - } - - TopTools_IndexedMapOfShape anIndices; - TopExp::MapShapes(_myShape, anIndices); - Handle(TColStd_HArray1OfInteger) anArray; - - TopTools_ListIteratorOfListOfShape itSub (listShape); - for (int index = 1; itSub.More(); itSub.Next(), ++index) { - TopoDS_Shape aValue = itSub.Value(); - aList.push_back(anIndices.FindIndex(aValue)); - } - - std::list::iterator it = aList.begin(); - switch ( theShapeType ) { - case TopAbs_VERTEX: /* Fill vertices ids */ + TopTools_MapOfShape mapShape; + TopTools_ListOfShape listShape; + + TopExp_Explorer exp(m_shape, TopAbs_ShapeEnum(shapeType)); + for (; exp.More(); exp.Next()) { - _myNbVertices = aList.size(); - if (_myIdsVertices != NULL) - delete _myIdsVertices; - _myIdsVertices = new int[_myNbVertices]; - for (int i = 0; it != aList.end(); it++, i++) - _myIdsVertices[i] = (*it); - break; + if (mapShape.Add(exp.Current())) + listShape.Append(exp.Current()); } - case TopAbs_EDGE: /* Fill edges ids */ + + if (listShape.IsEmpty()) { - _myNbEdges = aList.size(); - if (_myIdsEdges != NULL) - delete _myIdsEdges; - _myIdsEdges = new int[_myNbEdges]; - for (int i = 0; it != aList.end(); it++, i++) - _myIdsEdges[i] = (*it); - break; + return; } - case TopAbs_FACE: /* Fill faces ids */ + + TopTools_IndexedMapOfShape anIndices; + TopExp::MapShapes(m_shape, anIndices); + //Handle (TColStd_HArray1OfInteger) anArray; + + std::list aList; + TopTools_ListIteratorOfListOfShape itSub(listShape); + for (int index = 1; itSub.More(); itSub.Next(), ++index) { - _myNbFaces = aList.size(); - if (_myIdsFaces != NULL) - delete _myIdsFaces; - _myIdsFaces = new int[_myNbFaces]; - for (int i = 0; it != aList.end(); it++, i++) - _myIdsFaces[i] = (*it); - break; + TopoDS_Shape value = itSub.Value(); + aList.push_back(anIndices.FindIndex(value)); } - case TopAbs_SOLID: /* Fill solids ids */ + + std::list::iterator it = aList.begin(); + switch (shapeType) { - _myNbSolids = aList.size(); - if (_myIdsSolids != NULL) - delete _myIdsSolids; - _myIdsSolids = new int[_myNbSolids]; - for (int i = 0; it != aList.end(); it++, i++) - _myIdsSolids[i] = (*it); - break; + case TopAbs_VERTEX: /* Fill vertices ids */ + { + m_vertices.setSize(aList.size()); + for (int i = 0; it != aList.end(); it++, i++) + m_vertices.setReference(i, XaoUtils::intToString((*it))); + break; + } + case TopAbs_EDGE: /* Fill edges ids */ + { + m_edges.setSize(aList.size()); + for (int i = 0; it != aList.end(); it++, i++) + m_edges.setReference(i, XaoUtils::intToString((*it))); + break; + } + case TopAbs_FACE: /* Fill faces ids */ + { + m_faces.setSize(aList.size()); + for (int i = 0; it != aList.end(); it++, i++) + m_faces.setReference(i, XaoUtils::intToString((*it))); + break; + } + case TopAbs_SOLID: /* Fill solids ids */ + { + m_solids.setSize(aList.size()); + for (int i = 0; it != aList.end(); it++, i++) + m_solids.setReference(i, XaoUtils::intToString((*it))); + break; + } } - } - + } diff --git a/src/XAO/Geometry.hxx b/src/XAO/Geometry.hxx index 11accc149..a4580a752 100644 --- a/src/XAO/Geometry.hxx +++ b/src/XAO/Geometry.hxx @@ -26,58 +26,96 @@ #include #include +# include "GeometricElement.hxx" + namespace XAO -{ - class Geometry - { - public: - Geometry(); - ~Geometry(); - - void setName(const char *name) { _myName=name; } - const char *getName() const { return _myName.c_str(); } - - void setFormat(const char *format) { _myFormat=format; } - const char *getFormat() const { return _myFormat.c_str(); } - - void setShape(TopoDS_Shape Shape); - TopoDS_Shape getShape() { return _myShape; } - - void setShape(const char * brep ); - const char * getBREP(); - - int countVertices() { return _myNbVertices; } - int findVertex(int id); - void setVertexName(int index, const char *myName); - const char * getVertexName(int index) { return _myNamesVertices[index].c_str(); } - void changeVertexName(int id, const char *myName); - const char * findVertexName(int id); - - int countEdges() { return _myNbEdges; } - int countFaces() { return _myNbFaces; } - int countSolids() { return _myNbSolids; } - - - private: - void initListIds(const Standard_Integer theShapeType); - - private: - TopoDS_Shape _myShape; - std::string _myName; - std::string _myFormat; - int _myNbVertices; - std::string *_myNamesVertices; - int *_myIdsVertices; - int _myNbEdges; - std::string *_myNamesEdges; - int *_myIdsEdges; - int _myNbFaces; - std::string *_myNamesFaces; - int *_myIdsFaces; - int _myNbSolids; - std::string *_myNamesSolids; - int *_myIdsSolids; - }; +{ + class Geometry + { + public: + Geometry(); + ~Geometry(); + + const char* getName() + { + return m_name.c_str(); + } + void setName(const char* name) + { + m_name = name; + } + + const char* getFormat() + { + return m_format.c_str(); + } + void setFormat(const char* format) + { + m_format = format; + } + + TopoDS_Shape getShape() + { + return m_shape; + } + void setShape(TopoDS_Shape shape); + + const char* getBREP(); + void setShape(const char* brep); + + int countVertices() { return m_vertices.getSize(); } + int countEdges() { return m_edges.getSize(); } + int countFaces() { return m_faces.getSize(); } + int countSolids() { return m_solids.getSize(); } + + void setCountVertices(const int nb) { m_vertices.setSize(nb); } + void setCountEdges(const int nb) { m_edges.setSize(nb); } + void setCountFaces(const int nb) { m_faces.setSize(nb); } + void setCountSolids(const int nb) { m_solids.setSize(nb); } + + void setVertex(const int index, const char* name, const char* reference) { m_vertices.setElement(index, name,reference); } + void setEdge(const int index, const char* name, const char* reference) { m_edges.setElement(index, name,reference); } + void setFace(const int index, const char* name, const char* reference) { m_faces.setElement(index, name,reference); } + void setSolid(const int index, const char* name, const char* reference) { m_solids.setElement(index, name,reference); } + + const char* getVertexName(const int index) { return m_vertices.getName(index); } + const char* getEdgeName(const int index) { return m_edges.getName(index); } + const char* getFaceName(const int index) { return m_faces.getName(index); } + const char* getSolidName(const int index) { return m_solids.getName(index); } + + void setVertexName(const int index, const char* name) { m_vertices.setName(index, name); } + void setEdgeName(const int index, const char* name) { m_edges.setName(index, name); } + void setFaceName(const int index, const char* name) { m_faces.setName(index, name); } + void setSolidName(const int index, const char* name) { m_solids.setName(index, name); } + + const char* getVertexReference(const int index) { return m_vertices.getReference(index); } + const char* getEdgeReference(const int index) { return m_edges.getReference(index); } + const char* getFaceReference(const int index) { return m_faces.getReference(index); } + const char* getSolidReference(const int index) { return m_solids.getReference(index); } + + void setVertexReference(const int index, const char* reference) { m_vertices.setReference(index, reference); } + void setEdgeReference(const int index, const char* reference) { m_edges.setReference(index, reference); } + void setFaceReference(const int index, const char* reference) { m_faces.setReference(index, reference); } + void setSolidReference(const int index, const char* reference) { m_solids.setReference(index, reference); } + +// int findVertex(int id); +// void changeVertexName(const int id, const char* name); +// const char* findVertexName(int id); + + + private: + void initListIds(const Standard_Integer shapeType); + + private: + TopoDS_Shape m_shape; + std::string m_name; + std::string m_format; + GeometricElementList m_vertices; + GeometricElementList m_edges; + GeometricElementList m_faces; + GeometricElementList m_solids; + + }; } #endif diff --git a/src/XAO/Group.cxx b/src/XAO/Group.cxx index fbc862ad4..7c52ce1ce 100644 --- a/src/XAO/Group.cxx +++ b/src/XAO/Group.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2012 CEA/DEN, EDF R&D +// Copyright (C) 2013 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -16,7 +16,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// Author : Nathalie Gore (OpenCascade) +// Author : Nathalie Gore (OpenCascade), Frederic Pons (OpenCascade) #include "Group.hxx" @@ -24,12 +24,11 @@ using namespace XAO; Group::Group() { - _myType = 0; - _myCount = 0; + m_dimension = 0; + m_count = 0; } Group::~Group() { } - diff --git a/src/XAO/Group.hxx b/src/XAO/Group.hxx index 952bd319f..9f9a8c782 100644 --- a/src/XAO/Group.hxx +++ b/src/XAO/Group.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2012 CEA/DEN, EDF R&D +// Copyright (C) 2013 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -16,42 +16,61 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// Author : Nathalie Gore (OpenCascade) +// Author : Nathalie Gore (OpenCascade), Frederic Pons (OpenCascade) #ifndef __XAO_GROUP_HXX__ #define __XAO_GROUP_HXX__ #include -#include +#include namespace XAO { - class Group - { - public: - Group(); - ~Group(); - - void setName(const char *name) { _myName=name; } - const char *getName() const { return _myName.c_str(); } - - void setType(int type) { _myType=type; } - int getType() { return _myType; } - - int getCount() { return _myValues.size(); } - - void addValue(int value) {_myValues.push_back(value);} - //int getValue(int index) { return _myValues[index]; } - - private: - void sort() {_myValues.sort();} - - private: - std::string _myName; - int _myType; - int _myCount; - std::list _myValues; - }; + class Group + { + public: + Group(); + ~Group(); + + void setName(const char* name) + { + m_name = name; + } + const char *getName() const + { + return m_name.c_str(); + } + + void setDimension(int dimension) + { + m_dimension = dimension; + } + int getDimension() + { + return m_dimension; + } + + int getCount() + { + return m_elements.size(); + } + + void addElement(const char* value) + { + m_elements.push_back(value); + } + + const char* getElement(const int index) + { + return m_elements[index].c_str(); + } + + private: + std::string m_name; + int m_dimension; + int m_count; + std::vector m_elements; + }; } #endif diff --git a/src/XAO/Makefile.am b/src/XAO/Makefile.am index eae1a4414..2f7d7dd2d 100644 --- a/src/XAO/Makefile.am +++ b/src/XAO/Makefile.am @@ -21,7 +21,9 @@ # include $(top_srcdir)/adm_local/unix/make_common_starter.am - +if CPPUNIT_IS_OK + SUBDIRS = . tests +endif # =============================================================== # Files to be installed @@ -29,29 +31,32 @@ include $(top_srcdir)/adm_local/unix/make_common_starter.am # # header files salomeinclude_HEADERS = \ - Xao.hxx \ - Geometry.hxx \ - Group.hxx \ - Field.hxx + XaoUtils.hxx \ + GeometricElement.hxx \ + Xao.hxx \ + Geometry.hxx \ + Group.hxx \ + Field.hxx lib_LTLIBRARIES = libXAO.la dist_libXAO_la_SOURCES = \ - Xao.cxx \ - Geometry.cxx \ - Group.cxx \ - Field.cxx - + XaoUtils.cxx \ + GeometricElement.cxx \ + Xao.cxx \ + Geometry.cxx \ + Group.cxx \ + Field.cxx libXAO_la_CPPFLAGS = \ - $(GEOM_CXXFLAGS) \ - $(CAS_CPPFLAGS) \ - $(LIBXML_INCLUDES) \ - -I$(top_builddir) \ - -I$(top_builddir)/idl + $(GEOM_CXXFLAGS) \ + $(CAS_CPPFLAGS) \ + $(LIBXML_INCLUDES) \ + -I$(top_builddir) \ + -I$(top_builddir)/idl libXAO_la_LDFLAGS = \ - $(CAS_LDPATH) \ - $(LIBXML_LIBS) \ - $(GEOM_LDFLAGS) + $(CAS_LDPATH) \ + $(LIBXML_LIBS) \ + $(GEOM_LDFLAGS) diff --git a/src/XAO/Xao.cxx b/src/XAO/Xao.cxx index 179a2b7fd..2c2361a5a 100644 --- a/src/XAO/Xao.cxx +++ b/src/XAO/Xao.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2012 CEA/DEN, EDF R&D +// Copyright (C) 2013 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -16,78 +16,500 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// Author : Nathalie Gore (OpenCascade) +// Author : Nathalie Gore (OpenCascade), Frederic Pons (OpenCascade) +#include + +#include "XaoUtils.hxx" #include "Xao.hxx" #include "Geometry.hxx" #include "Group.hxx" #include "Field.hxx" +#include -#include -#include -#include -#include +using namespace XAO; -#include -#include -#include -#include -using namespace XAO; +const xmlChar* C_XAO_VERSION = (xmlChar*)"1.0"; + +const xmlChar* C_TAG_XAO = (xmlChar*)"XAO"; +const xmlChar* C_ATTR_XAO_AUTHOR = (xmlChar*)"author"; +const xmlChar* C_ATTR_XAO_VERSION = (xmlChar*)"version"; + +const xmlChar* C_TAG_GEOMETRY = (xmlChar*)"geometry"; +const xmlChar* C_ATTR_GEOMETRY_NAME = (xmlChar*)"name"; + +const xmlChar* C_TAG_SHAPE = (xmlChar*)"shape"; +const xmlChar* C_ATTR_SHAPE_FORMAT = (xmlChar*)"format"; + +const xmlChar* C_TAG_TOPOLOGY = (xmlChar*)"topology"; +const xmlChar* C_TAG_VERTICES = (xmlChar*)"vertices"; +const xmlChar* C_TAG_VERTEX = (xmlChar*)"vertex"; +const xmlChar* C_TAG_EDGES = (xmlChar*)"edges"; +const xmlChar* C_TAG_EDGE = (xmlChar*)"edge"; +const xmlChar* C_TAG_FACES = (xmlChar*)"faces"; +const xmlChar* C_TAG_FACE = (xmlChar*)"face"; +const xmlChar* C_TAG_SOLIDS = (xmlChar*)"solids"; +const xmlChar* C_TAG_SOLID = (xmlChar*)"solid"; +const xmlChar* C_ATTR_COUNT = (xmlChar*)"count"; +const xmlChar* C_ATTR_ELT_INDEX = (xmlChar*)"index"; +const xmlChar* C_ATTR_ELT_NAME = (xmlChar*)"name"; +const xmlChar* C_ATTR_ELT_REFERENCE = (xmlChar*)"reference"; + +const xmlChar* C_TAG_GROUPS = (xmlChar*)"groups"; +const xmlChar* C_TAG_GROUP = (xmlChar*)"group"; +const xmlChar* C_ATTR_GROUP_NAME = (xmlChar*)"name"; +const xmlChar* C_ATTR_GROUP_DIM = (xmlChar*)"dimension"; + +const xmlChar* C_TAG_ELEMENT = (xmlChar*)"element"; +const xmlChar* C_ATTR_ELEMENT_INDEX = (xmlChar*)"index"; + +const xmlChar* C_TAG_FIELDS = (xmlChar*)"fields"; +const xmlChar* C_TAG_FIELD = (xmlChar*)"field"; +const xmlChar* C_TAG_COMPONENTS = (xmlChar*)"components"; +const xmlChar* C_TAG_COMPONENT = (xmlChar*)"component"; +const xmlChar* C_TAG_STEPS = (xmlChar*)"steps"; +const xmlChar* C_TAG_STEP = (xmlChar*)"step"; Xao::Xao() { - _myAuthor = "Nathalie Gore"; - _myVersion = "1.0"; - _myGeometry = NULL; - _myNbGroups = 0; + m_author = ""; + m_version = (char*)C_XAO_VERSION; + m_geometry = NULL; + m_nbGroups = 0; } -Xao::Xao(const char *author, const char *version) +Xao::Xao(const char* author, const char* version) { - _myAuthor = author; - _myVersion = version; - _myGeometry = NULL; - _myNbGroups = 0; + m_author = author; + m_version = version; + m_geometry = NULL; + m_nbGroups = 0; } - Xao::~Xao() { - if (_myGeometry != NULL) - { - delete _myGeometry; - _myGeometry = NULL; - } -} - -bool Xao::Export(const char* fileName) -{ - if (_myGeometry == NULL) - return false; - - xmlDocPtr master_doc = 0; - xmlNodePtr xao_node = 0; - - //Creating the Xml document - master_doc = xmlNewDoc(BAD_CAST "1.0"); - xao_node = xmlNewNode(0, BAD_CAST "XAO"); - xmlDocSetRootElement(master_doc,xao_node); - - xmlNodePtr version_node = xmlNewChild(xao_node,0, BAD_CAST "version", BAD_CAST _myVersion.c_str()); - xmlNodePtr author_node = xmlNewChild(xao_node,0, BAD_CAST "author", BAD_CAST _myAuthor.c_str()); - - // Geometric part - xmlNodePtr geom_node = xmlNewChild(xao_node,0, BAD_CAST "geometry",0); - xmlNodePtr name_geom_node = xmlNewChild(geom_node,0, BAD_CAST "name",BAD_CAST _myGeometry->getName()); - xmlNodePtr format_geom_node = xmlNewChild(geom_node,0, BAD_CAST "name",BAD_CAST _myGeometry->getFormat()); - xmlNodePtr shape_geom_node = xmlNewChild(geom_node,0, BAD_CAST "shape",BAD_CAST _myGeometry->getBREP()); - - /*xmlNodePtr topo_geom_node = xmlNewChild(geom_node,0, BAD_CAST "topology",0); - ostringstream stream; - stream << _myGeometry->countVertices(); - xmlNodePtr count_topo_geom_node = xmlNewChild(count_topo_geom_node,0, BAD_CAST "topology", BAD_CAST stream.str().c_str());*/ - + if (m_geometry != NULL) + { + delete m_geometry; + m_geometry = NULL; + } + +// for (std::list::iterator it = m_groups.begin(); it != m_groups.end(); ++it) +// { +// delete (*it); +// } +} + +Group* Xao::getGroup(const int index) +{ + int i = 0; + for (std::list::iterator it = m_groups.begin(); it != m_groups.end(); ++it, ++i) + { + if (i == index) + return (*it); + } +} + + +bool Xao::exportToFile(const char* fileName) +{ + xmlDocPtr doc = exportXMLDoc(); + xmlSaveFormatFileEnc(fileName, doc, "UTF-8", 2); + xmlFreeDoc(doc); + return true; } +const char* Xao::getXML() +{ + xmlDocPtr doc = exportXMLDoc(); + + xmlChar *xmlbuff; + int buffersize; + xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1); + xmlFreeDoc(doc); + xmlCleanupGlobals(); + + return (char*)xmlbuff; +} + +xmlDocPtr Xao::exportXMLDoc() +{ + // Creating the Xml document + xmlDocPtr masterDocument = xmlNewDoc(BAD_CAST "1.0"); + xmlNodePtr xao = xmlNewNode(0, C_TAG_XAO); + xmlDocSetRootElement(masterDocument, xao); + + xmlNewProp(xao, C_ATTR_XAO_VERSION, BAD_CAST getVersion()); + xmlNewProp(xao, C_ATTR_XAO_AUTHOR, BAD_CAST getAuthor()); + + if (m_geometry != NULL) + { + exportGeometry(masterDocument, xao); + } + + exportGroups(xao); + + return masterDocument; +} + +void Xao::exportGeometry(xmlDocPtr doc, xmlNodePtr xao) +{ + // Geometric part + xmlNodePtr geometry = xmlNewChild(xao, 0, C_TAG_GEOMETRY, 0); + xmlNewProp(geometry, C_ATTR_GEOMETRY_NAME, BAD_CAST m_geometry->getName()); + + xmlNodePtr shape = xmlNewChild(geometry, 0, C_TAG_SHAPE, 0); + xmlNewProp(shape, C_ATTR_SHAPE_FORMAT, BAD_CAST m_geometry->getFormat()); + const char* brep = m_geometry->getBREP(); + xmlNodePtr cdata = xmlNewCDataBlock(doc, BAD_CAST brep, strlen(brep)); + xmlAddChild(shape, cdata); + + xmlNodePtr topology = xmlNewChild(geometry, 0, C_TAG_TOPOLOGY, 0); + + // vertices + xmlNodePtr vertices = xmlNewChild(topology, 0, C_TAG_VERTICES, 0); + xmlNewProp(vertices, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(m_geometry->countVertices())); + for (int i = 0; i < m_geometry->countVertices(); ++i) + { + xmlNodePtr vertex = xmlNewChild(vertices, 0, C_TAG_VERTEX, 0); + xmlNewProp(vertex, C_ATTR_ELT_INDEX, BAD_CAST XaoUtils::intToString(i)); + xmlNewProp(vertex, C_ATTR_ELT_NAME, BAD_CAST m_geometry->getVertexName(i)); + xmlNewProp(vertex, C_ATTR_ELT_REFERENCE, BAD_CAST m_geometry->getVertexReference(i)); + } + + // edges + xmlNodePtr edges = xmlNewChild(topology, 0, C_TAG_EDGES, 0); + xmlNewProp(edges, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(m_geometry->countEdges())); + for (int i = 0; i < m_geometry->countEdges(); ++i) + { + xmlNodePtr edge = xmlNewChild(edges, 0, C_TAG_EDGE, 0); + xmlNewProp(edge, C_ATTR_ELT_INDEX, BAD_CAST XaoUtils::intToString(i)); + xmlNewProp(edge, C_ATTR_ELT_NAME, BAD_CAST m_geometry->getEdgeName(i)); + xmlNewProp(edge, C_ATTR_ELT_REFERENCE, BAD_CAST m_geometry->getEdgeReference(i)); + } + + // faces + xmlNodePtr faces = xmlNewChild(topology, 0, C_TAG_FACES, 0); + xmlNewProp(faces, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(m_geometry->countFaces())); + for (int i = 0; i < m_geometry->countFaces(); ++i) + { + xmlNodePtr face = xmlNewChild(faces, 0, C_TAG_FACE, 0); + xmlNewProp(face, C_ATTR_ELT_INDEX, BAD_CAST XaoUtils::intToString(i)); + xmlNewProp(face, C_ATTR_ELT_NAME, BAD_CAST m_geometry->getFaceName(i)); + xmlNewProp(face, C_ATTR_ELT_REFERENCE, BAD_CAST m_geometry->getFaceReference(i)); + } + + // soldids + xmlNodePtr solids = xmlNewChild(topology, 0, C_TAG_SOLIDS, 0); + xmlNewProp(solids, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(m_geometry->countSolids())); + for (int i = 0; i < m_geometry->countSolids(); ++i) + { + xmlNodePtr solid = xmlNewChild(solids, 0, C_TAG_SOLID, 0); + xmlNewProp(solid, C_ATTR_ELT_INDEX, BAD_CAST XaoUtils::intToString(i)); + xmlNewProp(solid, C_ATTR_ELT_NAME, BAD_CAST m_geometry->getSolidName(i)); + xmlNewProp(solid, C_ATTR_ELT_REFERENCE, BAD_CAST m_geometry->getSolidReference(i)); + } +} + +void Xao::exportGroups(xmlNodePtr xao) +{ + xmlNodePtr groups = xmlNewChild(xao, 0, C_TAG_GROUPS, 0); + xmlNewProp(groups, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(countGroups())); + + for (std::list::iterator it = m_groups.begin(); it != m_groups.end(); ++it) + { + Group* grp = (*it); + xmlNodePtr group = xmlNewChild(groups, 0, C_TAG_GROUP, 0); + xmlNewProp(group, C_ATTR_GROUP_NAME, BAD_CAST grp->getName()); + xmlNewProp(group, C_ATTR_GROUP_DIM, BAD_CAST XaoUtils::dimensionToString(grp->getDimension())); + xmlNewProp(group, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(grp->getCount())); + + for (int i = 0; i < grp->getCount(); ++i) + { + xmlNodePtr elt = xmlNewChild(group, 0, C_TAG_ELEMENT, 0); + xmlNewProp(elt, C_ATTR_ELEMENT_INDEX, BAD_CAST grp->getElement(i)); + } + } +} + +bool Xao::importFromFile(const char* fileName) +{ + // parse the file and get the DOM + int options = 16384; // merge cdata as text node + xmlDocPtr doc = xmlReadFile(fileName, NULL, options); + if (doc == NULL) + { + throw SALOME_Exception("Cannot read XAO file"); + } + + parseXMLDoc(doc); + return true; +} + +void Xao::parseXMLDoc(xmlDocPtr doc) +{ + // Get the root element node + xmlNodePtr root = xmlDocGetRootElement(doc); + if (xmlStrcmp(root->name , C_TAG_XAO) != 0) + throw SALOME_Exception("Cannot read XAO file: invalid format XAO node not found"); + + parseXaoNode(doc, root); + + xmlFreeDoc(doc); // free document + xmlCleanupParser(); // Free globals +} + +void Xao::parseXaoNode(xmlDocPtr doc, xmlNodePtr xaoNode) +{ + xmlChar* version = xmlGetProp(xaoNode, C_ATTR_XAO_VERSION); + if (version != NULL) + { + setVersion((char*)version); + xmlFree(version); + } + + xmlChar* author = xmlGetProp(xaoNode, C_ATTR_XAO_AUTHOR); + if (author != NULL) + { + setAuthor((char*)author); + xmlFree(author); + } + + for (xmlNodePtr node = xaoNode->children; node; node = node->next) + { + if (xmlStrcmp(node->name, C_TAG_GEOMETRY) == 0) + parseGeometryNode(doc, node); + else if (xmlStrcmp(node->name, C_TAG_GROUPS) == 0) + parseGroupsNode(node); + } +} + +void Xao::parseGeometryNode(xmlDocPtr doc, xmlNodePtr geometryNode) +{ + //std::cout << ">> Geometry" << std::endl; + if (m_geometry == NULL) + m_geometry = new Geometry(); + + xmlChar* name = xmlGetProp(geometryNode, C_ATTR_GEOMETRY_NAME); + if (name != NULL) + { + m_geometry->setName((char*)name); + xmlFree(name); + } + + for (xmlNodePtr node = geometryNode->children; node; node = node->next) + { + if (xmlStrcmp(node->name, C_TAG_SHAPE) == 0) + parseShapeNode(doc, node); + else if (xmlStrcmp(node->name, C_TAG_TOPOLOGY) == 0) + parseTopologyNode(node); +// else +// std::cout << "skip:" << node->name << std::endl; + } + +} + +void Xao::parseShapeNode(xmlDocPtr doc, xmlNodePtr shapeNode) +{ + xmlChar* shapeType = xmlGetProp(shapeNode, C_ATTR_SHAPE_FORMAT); + if (xmlStrcmp(shapeType, (xmlChar*)"BREP") == 0) + { + xmlChar* data = xmlNodeGetContent(shapeNode->children); + if (data == NULL) + throw SALOME_Exception("Missing BREP"); + m_geometry->setShape((char*)data); + xmlFree(data); + } + else + { + throw SALOME_Exception("Shape format not supported"); + } +} + +void Xao::parseTopologyNode(xmlNodePtr topologyNode) +{ +// std::cout << ">> Topology" << std::endl; + for (xmlNodePtr node = topologyNode->children; node; node = node->next) + { + if (xmlStrcmp(node->name, C_TAG_VERTICES) == 0) + parseVerticesNode(node); + else if (xmlStrcmp(node->name, C_TAG_EDGES) == 0) + parseEdgesNode(node); + else if (xmlStrcmp(node->name, C_TAG_FACES) == 0) + parseFacesNode(node); + else if (xmlStrcmp(node->name, C_TAG_SOLIDS) == 0) + parseSolidsNode(node); + } +} +void Xao::parseVerticesNode(xmlNodePtr verticesNode) +{ + xmlChar* count = xmlGetProp(verticesNode, C_ATTR_COUNT); + if (count == NULL) + throw SALOME_Exception("No count attribute for vertices"); + + m_geometry->setCountVertices(atoi((char*)count)); + xmlFree(count); + + for (xmlNodePtr node = verticesNode->children; node; node = node->next) + { + if (xmlStrcmp(node->name, C_TAG_VERTEX) == 0) + { + xmlChar* index = xmlGetProp(node, C_ATTR_ELT_INDEX); + if (index == NULL) + throw SALOME_Exception("Bad index for vertex"); + + xmlChar* name = xmlGetProp(node, C_ATTR_ELT_NAME); + if (name == NULL) + name = (xmlChar*)""; + + xmlChar* reference = xmlGetProp(node, C_ATTR_ELT_REFERENCE); + if (reference == NULL) + throw SALOME_Exception("Bad reference for vertex"); + + m_geometry->setVertex(atoi((char*)index), (char*)name, (char*)reference); + } + } +} + +void Xao::parseEdgesNode(xmlNodePtr edgesNode) +{ + xmlChar* count = xmlGetProp(edgesNode, C_ATTR_COUNT); + if (count == NULL) + throw SALOME_Exception("No count attribute for edges"); + + m_geometry->setCountEdges(atoi((char*)count)); + xmlFree(count); + + for (xmlNodePtr node = edgesNode->children; node; node = node->next) + { + if (xmlStrcmp(node->name, C_TAG_EDGE) == 0) + { + xmlChar* index = xmlGetProp(node, C_ATTR_ELT_INDEX); + if (index == NULL) + throw SALOME_Exception("Bad index for edge"); + + xmlChar* name = xmlGetProp(node, C_ATTR_ELT_NAME); + if (name == NULL) + name = (xmlChar*)""; + + xmlChar* reference = xmlGetProp(node, C_ATTR_ELT_REFERENCE); + if (reference == NULL) + throw SALOME_Exception("Bad reference for edge"); + + m_geometry->setEdge(atoi((char*)index), (char*)name, (char*)reference); + } + } +} + +void Xao::parseFacesNode(xmlNodePtr facesNode) +{ + xmlChar* count = xmlGetProp(facesNode, C_ATTR_COUNT); + if (count == NULL) + throw SALOME_Exception("No count attribute for faces"); + + m_geometry->setCountFaces(atoi((char*)count)); + xmlFree(count); + + for (xmlNodePtr node = facesNode->children; node; node = node->next) + { + if (xmlStrcmp(node->name, C_TAG_FACE) == 0) + { + xmlChar* index = xmlGetProp(node, C_ATTR_ELT_INDEX); + if (index == NULL) + throw SALOME_Exception("Bad index for face"); + + xmlChar* name = xmlGetProp(node, C_ATTR_ELT_NAME); + if (name == NULL) + name = (xmlChar*)""; + + xmlChar* reference = xmlGetProp(node, C_ATTR_ELT_REFERENCE); + if (reference == NULL) + throw SALOME_Exception("Bad reference for face"); + + m_geometry->setFace(atoi((char*)index), (char*)name, (char*)reference); + } + } +} + +void Xao::parseSolidsNode(xmlNodePtr solidsNode) +{ + xmlChar* count = xmlGetProp(solidsNode, C_ATTR_COUNT); + if (count == NULL) + throw SALOME_Exception("No count attribute for solids"); + + m_geometry->setCountSolids(atoi((char*)count)); + xmlFree(count); + + for (xmlNodePtr node = solidsNode->children; node; node = node->next) + { + if (xmlStrcmp(node->name, C_TAG_SOLID) == 0) + { + xmlChar* index = xmlGetProp(node, C_ATTR_ELT_INDEX); + if (index == NULL) + throw SALOME_Exception("Bad index for solid"); + + xmlChar* name = xmlGetProp(node, C_ATTR_ELT_NAME); + if (name == NULL) + name = (xmlChar*)""; + + xmlChar* reference = xmlGetProp(node, C_ATTR_ELT_REFERENCE); + if (reference == NULL) + throw SALOME_Exception("Bad reference for solid"); + + m_geometry->setSolid(atoi((char*)index), (char*)name, (char*)reference); + } + } +} + +void Xao::parseGroupsNode(xmlNodePtr groupsNode) +{ +// xmlChar* count = xmlGetProp(groupsNode, C_ATTR_COUNT); +// if (count == NULL) +// throw SALOME_Exception("No count attribute for groups"); + + for (xmlNodePtr node = groupsNode->children; node; node = node->next) + { + if (xmlStrcmp(node->name, C_TAG_GROUP) == 0) + { + parseGroupNode(node); + } + } +} + +void Xao::parseGroupNode(xmlNodePtr groupNode) +{ +// xmlChar* count = xmlGetProp(groupNode, C_ATTR_COUNT); +// if (count == NULL) +// throw SALOME_Exception("Bad count for group"); + + xmlChar* dimension = xmlGetProp(groupNode, C_ATTR_GROUP_DIM); + if (dimension == NULL) + throw SALOME_Exception("Bad dimension for group"); + + Group* group = new Group(); + + xmlChar* name = xmlGetProp(groupNode, C_ATTR_GROUP_NAME); + if (name == NULL) name = (xmlChar*)""; + group->setName((char*)name); + xmlFree(name); + + group->setDimension(XaoUtils::stringToDimension((char*)dimension)); + xmlFree(dimension); + + addGroup(group); + + for (xmlNodePtr node = groupNode->children; node; node = node->next) + { + if (xmlStrcmp(node->name, C_TAG_ELEMENT) == 0) + { + xmlChar* index = xmlGetProp(node, C_ATTR_ELEMENT_INDEX); + if (index == NULL) + throw SALOME_Exception("Bad index for group element"); + group->addElement((char*)index); + xmlFree(index); + } + } + +} diff --git a/src/XAO/Xao.hxx b/src/XAO/Xao.hxx index 09a695845..e7d28a8bc 100644 --- a/src/XAO/Xao.hxx +++ b/src/XAO/Xao.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2012 CEA/DEN, EDF R&D +// Copyright (C) 2013 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -16,61 +16,84 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// Author : Nathalie Gore (OpenCascade) +// Author : Nathalie Gore (OpenCascade), Frederic Pons (OpenCascade) #ifndef __XAO_XAO_HXX__ #define __XAO_XAO_HXX__ #include #include +#include namespace XAO { - enum Kind{ + enum Kind + { VERTEX, EDGE, FACE, SOLID }; - + class Geometry; class Group; class Field; - + class Xao { public: Xao(); - Xao(const char *author, const char *version); + Xao(const char* author, const char* version); ~Xao(); - void setAuthor(const char *author) { _myAuthor=author; } - const char *getAuthor() const { return _myAuthor.c_str(); } - - void setVersion(const char *version) { _myVersion=version; } - const char *getVersion() const { return _myVersion.c_str(); } + void setAuthor(const char* author) { m_author = author; } + const char* getAuthor() { return m_author.c_str(); } + + void setVersion(const char* version) { m_version = version; } + const char* getVersion() { return m_version.c_str(); } + + void setGeometry(Geometry* geometry) { m_geometry = geometry; } + Geometry* getGeometry() { return m_geometry; } - void setGeometry(Geometry *myGeometry) { _myGeometry=myGeometry; } - const Geometry *getGeometry() const { return _myGeometry; } + int countGroups() { return m_groups.size(); } + Group* getGroup(const int index); + void addGroup(Group* group) { m_groups.push_back(group); } + void removeGroup(Group* group) { m_groups.remove(group); } - int getNbGroups() { return _myGroups.size(); } - void addGroup(Group *myGroup) { _myGroups.push_back(myGroup); } - void removeGroup(Group *myGroup) { _myGroups.remove(myGroup); } + bool exportToFile(const char* fileName); + const char* getXML(); - int getNbFields() { return _myNbFields; } - - bool Export(const char* fileName); + bool importFromFile(const char* fileName); + bool setXML(const char* xml); private: - std::string _myAuthor; - std::string _myVersion; - Geometry *_myGeometry; - int _myNbGroups; - std::list _myGroups; - int _myNbFields; - //std::list _myFields; + std::string m_author; + std::string m_version; + Geometry* m_geometry; + int m_nbGroups; + std::list m_groups; + //int m_nbFields; + //std::list m_fields; + + xmlDocPtr exportXMLDoc(); + void exportGeometry(xmlDocPtr doc, xmlNodePtr xao); + void exportGroups(xmlNodePtr xao); + + void parseXMLDoc(xmlDocPtr doc); + void parseXaoNode(xmlDocPtr doc, xmlNodePtr xaoNode); + void parseGeometryNode(xmlDocPtr doc, xmlNodePtr geometryNode); + void parseShapeNode(xmlDocPtr doc, xmlNodePtr shapeNode); + void parseTopologyNode(xmlNodePtr topologyNode); + void parseVerticesNode(xmlNodePtr verticesNode); + void parseEdgesNode(xmlNodePtr edgesNode); + void parseFacesNode(xmlNodePtr facesNode); + void parseSolidsNode(xmlNodePtr solidsNode); + void parseGroupsNode(xmlNodePtr groupsNode); + void parseGroupNode(xmlNodePtr groupNode); + }; + } #endif diff --git a/src/XAO/XaoUtils.cxx b/src/XAO/XaoUtils.cxx new file mode 100644 index 000000000..1caf8c61f --- /dev/null +++ b/src/XAO/XaoUtils.cxx @@ -0,0 +1,61 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Frederic Pons (OpenCascade) + +#include +#include +#include +#include +#include "XaoUtils.hxx" + + +using namespace XAO; + +const char* XaoUtils::intToString(const int value) +{ + std::stringstream str; + str << value; + return str.str().c_str(); +} + +const char* XaoUtils::dimensionToString(const int dimension) +{ + if (dimension == 0) + return "vertex"; + if (dimension == 1) + return "edge"; + if (dimension == 2) + return "face"; + if (dimension == 3) + return "solid"; + throw SALOME_Exception("Bad dimension"); +} + +const int XaoUtils::stringToDimension(const char* dimension) +{ + if (strcmp(dimension, "vertex") == 0) + return 0; + if (strcmp(dimension, "edge") == 0) + return 1; + if (strcmp(dimension, "face") == 0) + return 2; + if (strcmp(dimension, "solid") == 0) + return 3; + throw SALOME_Exception("Bad dimension"); +} diff --git a/src/XAO/XaoUtils.hxx b/src/XAO/XaoUtils.hxx new file mode 100644 index 000000000..aac50817a --- /dev/null +++ b/src/XAO/XaoUtils.hxx @@ -0,0 +1,37 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Frederic Pons (OpenCascade) + +#ifndef __XAO_UTILS_HXX__ +#define __XAO_UTILS_HXX__ + +namespace XAO +{ + class XaoUtils + { + public: + static const char* intToString(const int value); + static const char* dimensionToString(const int dimension); + static const int stringToDimension(const char* dimension); + }; +} + + + +#endif /* __XAO_UTILS_HXX__ */ diff --git a/src/XAO/tests/ImportExportTest.cxx b/src/XAO/tests/ImportExportTest.cxx new file mode 100644 index 000000000..31ccd85cd --- /dev/null +++ b/src/XAO/tests/ImportExportTest.cxx @@ -0,0 +1,167 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Frederic Pons (OpenCascade) + +#include +#include + +#include "ImportExportTest.hxx" +#include "../Geometry.hxx" +#include "../Group.hxx" + +using namespace XAO; + +std::string getTestFile(std::string fileName) +{ + std::string dataDir = getenv("GEOM_SRC_DIR"); + dataDir += "/src/XAO/tests/data/" + fileName; + return dataDir; +} + +void ImportExportTest::setUp() +{ +} + +void ImportExportTest::tearDown() +{ +} + +void ImportExportTest::cleanUp() +{ +} + +void ImportExportTest::testExportNoGeometry() +{ + Xao xao("me", "1.0"); + + bool res = xao.exportToFile("empty.xao"); + CPPUNIT_ASSERT(res); +} + +void ImportExportTest::testExportGeometry() +{ + Xao xao("me", "1.0"); + Geometry* geom = new Geometry(); + geom->setName("mygeom"); + xao.setGeometry(geom); + + geom->setCountVertices(4); + geom->setVertex(0, "v1", "1"); + geom->setVertex(1, "", "2"); + geom->setVertex(2, "v3", "3"); + geom->setVertex(3, "", "4"); + + geom->setCountEdges(3); + geom->setEdge(0, "e1", "5"); + geom->setEdge(1, "", "6"); + geom->setEdge(2, "e3", "7"); + + geom->setCountFaces(2); + geom->setFace(0, "f1", "8"); + geom->setFace(1, "", "9"); + + geom->setCountSolids(1); + geom->setSolid(0, "s1", "10"); + + Group* group = new Group(); + xao.addGroup(group); + group->setName("boite1"); + group->setDimension(3); + group->addElement("1"); + + group = new Group(); + xao.addGroup(group); + group->setName("faces"); + group->setDimension(2); + group->addElement("5"); + group->addElement("8"); + group->addElement("9"); + + bool res = xao.exportToFile("mygeom.xao"); + CPPUNIT_ASSERT(res); + + const char* xml = xao.getXML(); + //CPPUNIT_ASSERT(strlen(xml) == 1007); +} + +void ImportExportTest::testGeometryError() +{ + Xao xao("me", "1.0"); + Geometry* geom = new Geometry(); + geom->setName("mygeom"); + xao.setGeometry(geom); + + geom->setCountVertices(2); + CPPUNIT_ASSERT_THROW(geom->setVertex(3, "v4", "4"), SALOME_Exception); +} + +void ImportExportTest::testImportXao() +{ + std::cout << std::endl; + Xao xao; + xao.importFromFile(getTestFile("test.xao").c_str()); + CPPUNIT_ASSERT(strcmp(xao.getAuthor(), "me") == 0); + CPPUNIT_ASSERT(strcmp(xao.getVersion(), "1.0") == 0); + + Geometry* geom = xao.getGeometry(); + CPPUNIT_ASSERT(geom != NULL); + CPPUNIT_ASSERT(strcmp(geom->getName(), "mygeom") == 0); + + CPPUNIT_ASSERT(geom->countVertices() == 4); + CPPUNIT_ASSERT(strcmp(geom->getVertexName(0), "v1") == 0); + CPPUNIT_ASSERT(strcmp(geom->getVertexReference(0), "1") == 0); + CPPUNIT_ASSERT(strcmp(geom->getVertexName(1), "") == 0); + CPPUNIT_ASSERT(strcmp(geom->getVertexReference(1), "2") == 0); + CPPUNIT_ASSERT(strcmp(geom->getVertexName(2), "v3") == 0); + CPPUNIT_ASSERT(strcmp(geom->getVertexReference(2), "3") == 0); + CPPUNIT_ASSERT(strcmp(geom->getVertexName(3), "") == 0); + CPPUNIT_ASSERT(strcmp(geom->getVertexReference(3), "4") == 0); + + CPPUNIT_ASSERT(geom->countEdges() == 3); + CPPUNIT_ASSERT(strcmp(geom->getEdgeName(0), "e1") == 0); + CPPUNIT_ASSERT(strcmp(geom->getEdgeReference(0), "5") == 0); + CPPUNIT_ASSERT(strcmp(geom->getEdgeName(1), "") == 0); + CPPUNIT_ASSERT(strcmp(geom->getEdgeReference(1), "6") == 0); + CPPUNIT_ASSERT(strcmp(geom->getEdgeName(2), "e3") == 0); + CPPUNIT_ASSERT(strcmp(geom->getEdgeReference(2), "7") == 0); + + CPPUNIT_ASSERT(geom->countFaces() == 2); + CPPUNIT_ASSERT(strcmp(geom->getFaceName(0), "f1") == 0); + CPPUNIT_ASSERT(strcmp(geom->getFaceReference(0), "8") == 0); + CPPUNIT_ASSERT(strcmp(geom->getFaceName(1), "") == 0); + CPPUNIT_ASSERT(strcmp(geom->getFaceReference(1), "9") == 0); + + CPPUNIT_ASSERT(geom->countSolids() == 1); + CPPUNIT_ASSERT(strcmp(geom->getSolidName(0), "s1") == 0); + CPPUNIT_ASSERT(strcmp(geom->getSolidReference(0), "10") == 0); + + CPPUNIT_ASSERT(xao.countGroups() == 2); + Group* group = xao.getGroup(0); + CPPUNIT_ASSERT(group->getCount() == 1); + CPPUNIT_ASSERT(strcmp(group->getName(), "boite_1") == 0); + CPPUNIT_ASSERT(group->getDimension() == 3); + CPPUNIT_ASSERT(strcmp(group->getElement(0), "1") == 0); + group = xao.getGroup(1); + CPPUNIT_ASSERT(group->getCount() == 3); + CPPUNIT_ASSERT(strcmp(group->getName(), "") == 0); + CPPUNIT_ASSERT(group->getDimension() == 2); + CPPUNIT_ASSERT(strcmp(group->getElement(0), "5") == 0); + CPPUNIT_ASSERT(strcmp(group->getElement(1), "8") == 0); + CPPUNIT_ASSERT(strcmp(group->getElement(2), "9") == 0); +} diff --git a/src/XAO/tests/ImportExportTest.hxx b/src/XAO/tests/ImportExportTest.hxx new file mode 100644 index 000000000..a2be0f415 --- /dev/null +++ b/src/XAO/tests/ImportExportTest.hxx @@ -0,0 +1,31 @@ +#ifndef __BUILDING_IMPORT_TEST_HXX__ +#define __BUILDING_IMPORT_TEST_HXX__ + +#include + +#include "../Xao.hxx" + +namespace XAO +{ + class ImportExportTest: public CppUnit::TestFixture + { + CPPUNIT_TEST_SUITE(ImportExportTest); + CPPUNIT_TEST(testExportNoGeometry); + CPPUNIT_TEST(testExportGeometry); + CPPUNIT_TEST(testGeometryError); + CPPUNIT_TEST(testImportXao); + CPPUNIT_TEST_SUITE_END(); + + public: + void setUp(); + void tearDown(); + void cleanUp(); + + void testExportNoGeometry(); + void testExportGeometry(); + void testGeometryError(); + void testImportXao(); + }; +} + +#endif diff --git a/src/XAO/tests/MainTest.hxx b/src/XAO/tests/MainTest.hxx new file mode 100644 index 000000000..904c2a697 --- /dev/null +++ b/src/XAO/tests/MainTest.hxx @@ -0,0 +1,161 @@ +// Copyright (C) 2013 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Frederic Pons (OpenCascade) + +#ifndef __XAOMAINTEST_HXX__ +#define __XAOMAINTEST_HXX__ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +struct Arguments +{ +public: + bool List; + bool Err; + std::string Test; +}; + +Arguments parseArguments(int argc, char* argv[]) +{ + Arguments res; + res.List = false; + res.Err = false; + res.Test = ""; + + if (argc > 1) + { + int i = 0; + while (++i < argc) // skip 0 + { + if (strcmp(argv[i], "-l") == 0 || strcmp(argv[i], "--list") == 0) + { + res.List = true; + } + else if (strcmp(argv[i], "-e") == 0 || strcmp(argv[i], "--err") == 0) + { + res.Err = true; + } + if (strcmp(argv[i], "-t") == 0 || strcmp(argv[i], "--test") == 0) + { + if (i+1 < argc) + res.Test = argv[++i]; + } + } + } + + return res; +} + +void listTests(CPPUNIT_NS::Test* test) +{ + if (!test) return; + std::cout << test->getName() << std::endl; + for (int i = 0; i < test->getChildTestCount(); ++i) + { + listTests(test->getChildTestAt(i)); + } +} + +// ============================================================================ +/*! + * Main program source for Unit Tests with cppunit package does not depend + * on actual tests, so we use the same for all partial unit tests. + */ +// ============================================================================ +int main(int argc, char* argv[]) +{ + Arguments args = parseArguments(argc, argv); + + // --- Create the event manager and test controller + CPPUNIT_NS::TestResult controller; + + // --- Add a listener that colllects test result + CPPUNIT_NS::TestResultCollector result; + controller.addListener(&result); + + // --- Add a listener that print dots as test run. +#ifdef WIN32 + CPPUNIT_NS::TextTestProgressListener progress; +#else + CPPUNIT_NS::BriefTestProgressListener progress; +#endif + controller.addListener(&progress); + + // --- Get the top level suite from the registry + + CPPUNIT_NS::Test *suite = + CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest(); + + // --- Adds the test to the list of test to run + + // list tests and exit + if (args.List) + { + listTests(suite); + return 0; + } + + if (!args.Test.empty()) + { + // find test by name + // an exception is raised if not found + suite = suite->findTest(args.Test); + } + + CPPUNIT_NS::TestRunner runner; + runner.addTest(suite); + runner.run(controller); + + // --- Print test in a compiler compatible format. + + if (args.Err) + { + CPPUNIT_NS::CompilerOutputter outputter(&result, std::cerr); + outputter.write(); + } + else + { + std::ofstream testFile; + testFile.open("UnitTestsResult", std::ios::out | std::ios::trunc); + CPPUNIT_NS::CompilerOutputter outputter(&result, testFile); + outputter.write(); + testFile.close(); + } + + // --- Run the tests. + + bool wasSucessful = result.wasSuccessful(); + + // --- Return error code 1 if the one of test failed. + + return wasSucessful ? 0 : 1; +} + +#endif diff --git a/src/XAO/tests/Makefile.am b/src/XAO/tests/Makefile.am new file mode 100755 index 000000000..1efe609a0 --- /dev/null +++ b/src/XAO/tests/Makefile.am @@ -0,0 +1,32 @@ + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +bin_PROGRAMS= TestXAO + +TestXAO_CPPFLAGS= \ + @CPPUNIT_INCLUDES@ @PTHREAD_CFLAGS@ \ + $(GEOM_CXXFLAGS) \ + $(CAS_CPPFLAGS) \ + $(LIBXML_INCLUDES) \ + -I$(srcdir) + +TestXAO_LDFLAGS = \ + @CPPUNIT_LIBS@ \ + $(CAS_LDPATH) \ + $(LIBXML_LIBS) \ + $(GEOM_LDFLAGS) \ + -lxml2 \ + ../../GEOMBase/libGEOMBase.la \ + ../libXAO.la + +dist_TestXAO_SOURCES = \ + ImportExportTest.cxx \ + XAOTests.cxx + +UNIT_TEST_PROG = TestXAO + +check : tests + +CLEANFILES = \ + UnitTestsResult + diff --git a/src/XAO/tests/XAOTests.cxx b/src/XAO/tests/XAOTests.cxx new file mode 100644 index 000000000..daa59ca2d --- /dev/null +++ b/src/XAO/tests/XAOTests.cxx @@ -0,0 +1,5 @@ +#include "ImportExportTest.hxx" + +CPPUNIT_TEST_SUITE_REGISTRATION(XAO::ImportExportTest); + +#include "MainTest.hxx" diff --git a/src/XAO/tests/data/test.xao b/src/XAO/tests/data/test.xao new file mode 100644 index 000000000..010aa082f --- /dev/null +++ b/src/XAO/tests/data/test.xao @@ -0,0 +1,321 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.39.2