import/export XAO for topology and groups + rework

This commit is contained in:
fps 2013-04-09 12:00:09 +00:00
parent e508f5a4cc
commit 37b0d2eb73
28 changed files with 2273 additions and 726 deletions

View File

@ -359,6 +359,14 @@ echo
CHECK_KERNEL CHECK_KERNEL
echo
echo ---------------------------------------------
echo Testing cppunit
echo ---------------------------------------------
echo
CHECK_CPPUNIT
echo echo
echo --------------------------------------------- echo ---------------------------------------------
echo Summary echo Summary
@ -373,7 +381,7 @@ fi
echo 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" 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" gui_vars="OpenGL_ok qt_ok gui_ok"
### ###
@ -496,6 +504,7 @@ AC_OUTPUT([ \
src/Makefile \ src/Makefile \
src/AdvancedGUI/Makefile \ src/AdvancedGUI/Makefile \
src/XAO/Makefile \ src/XAO/Makefile \
src/XAO/tests/Makefile \
src/ImportExportGUI/Makefile \ src/ImportExportGUI/Makefile \
src/ARCHIMEDE/Makefile \ src/ARCHIMEDE/Makefile \
src/BREPExport/Makefile \ src/BREPExport/Makefile \

View File

@ -5762,9 +5762,13 @@ Do you want to create new material?</translation>
</context> </context>
<context> <context>
<name>@default</name> <name>@default</name>
<message>
<source>MEN_IMPORTEXPORT</source>
<translation>Import / Export</translation>
</message>
<message> <message>
<source>TOP_EXPORTXAO</source> <source>TOP_EXPORTXAO</source>
<translation>ExportXAO</translation> <translation>Export to XAO</translation>
</message> </message>
<message> <message>
<source>MEN_EXPORTXAO</source> <source>MEN_EXPORTXAO</source>
@ -5772,7 +5776,7 @@ Do you want to create new material?</translation>
</message> </message>
<message> <message>
<source>STB_EXPORTXAO</source> <source>STB_EXPORTXAO</source>
<translation>ExportXAO</translation> <translation>Export shape to XAO format</translation>
</message> </message>
<message> <message>
<source>GEOM_IMPORTEXPORT_204</source> <source>GEOM_IMPORTEXPORT_204</source>

View File

@ -19,6 +19,10 @@
// File : GEOMImpl_IImportExportOperations.cxx // File : GEOMImpl_IImportExportOperations.cxx
// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
#include <cmath>
#include <iostream>
#include <sstream>
#include <Standard_Stream.hxx> #include <Standard_Stream.hxx>
#include "GEOMImpl_Types.hxx" #include "GEOMImpl_Types.hxx"
@ -46,6 +50,7 @@
#include "Xao.hxx" #include "Xao.hxx"
#include "Geometry.hxx" #include "Geometry.hxx"
#include "Group.hxx" #include "Group.hxx"
#include "XaoUtils.hxx"
#include <GEOMImpl_ExportXAODriver.hxx> #include <GEOMImpl_ExportXAODriver.hxx>
#include <GEOMImpl_IExportXAO.hxx> #include <GEOMImpl_IExportXAO.hxx>
@ -68,7 +73,9 @@
#include <gp_Ax3.hxx> #include <gp_Ax3.hxx>
#include <BRepBuilderAPI_Transform.hxx> #include <BRepBuilderAPI_Transform.hxx>
#include <BRep_Tool.hxx> #include <BRep_Tool.hxx>
#include <cmath> #include <BRep_Builder.hxx>
#include <BRepTools.hxx>
#include <TFunction_DriverTable.hxx> #include <TFunction_DriverTable.hxx>
#include <TFunction_Driver.hxx> #include <TFunction_Driver.hxx>
@ -76,14 +83,13 @@
#include <TDF_Tool.hxx> #include <TDF_Tool.hxx>
#include <Standard_Failure.hxx> #include <Standard_Failure.hxx>
#include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
//============================================================================= //=============================================================================
/*! /*!
* Constructor * Constructor
*/ */
//============================================================================= //=============================================================================
GEOMImpl_IImportExportOperations::GEOMImpl_IImportExportOperations(GEOM_Engine* theEngine, int theDocID) : GEOMImpl_IImportExportOperations::GEOMImpl_IImportExportOperations(GEOM_Engine* engine, int docID) :
GEOM_IOperations(theEngine, theDocID) GEOM_IOperations(engine, docID)
{ {
MESSAGE("GEOMImpl_IImportExportOperations::GEOMImpl_IImportExportOperations"); MESSAGE("GEOMImpl_IImportExportOperations::GEOMImpl_IImportExportOperations");
/*myBasicOperations = new GEOMImpl_IBasicOperations(GetEngine(), GetDocID()); /*myBasicOperations = new GEOMImpl_IBasicOperations(GetEngine(), GetDocID());
@ -94,8 +100,8 @@ GEOMImpl_IImportExportOperations::GEOMImpl_IImportExportOperations(GEOM_Engine*
my3DPrimOperations = new GEOMImpl_I3DPrimOperations(GetEngine(), GetDocID()); my3DPrimOperations = new GEOMImpl_I3DPrimOperations(GetEngine(), GetDocID());
myLocalOperations = new GEOMImpl_ILocalOperations(GetEngine(), GetDocID()); myLocalOperations = new GEOMImpl_ILocalOperations(GetEngine(), GetDocID());
myHealingOperations = new GEOMImpl_IHealingOperations(GetEngine(), GetDocID());*/ myHealingOperations = new GEOMImpl_IHealingOperations(GetEngine(), GetDocID());*/
myShapesOperations = new GEOMImpl_IShapesOperations(GetEngine(), GetDocID()); m_shapesOperations = new GEOMImpl_IShapesOperations(GetEngine(), GetDocID());
myGroupOperations = new GEOMImpl_IGroupOperations(GetEngine(), GetDocID()); m_groupOperations = new GEOMImpl_IGroupOperations(GetEngine(), GetDocID());
} }
//============================================================================= //=============================================================================
@ -114,40 +120,48 @@ GEOMImpl_IImportExportOperations::~GEOMImpl_IImportExportOperations()
delete my3DPrimOperations; delete my3DPrimOperations;
delete myLocalOperations; delete myLocalOperations;
delete myHealingOperations;*/ delete myHealingOperations;*/
delete myShapesOperations; delete m_shapesOperations;
delete myGroupOperations; delete m_groupOperations;
} }
//============================================================================= //=============================================================================
/*! /*!
* Export a shape to XAO Format * Export a shape to XAO Format
* \param theExportingShape Shape to export * \param shape The shape to export
* \param theFileName The name of the exported file * \param fileName The name of the exported file
* \param thelGroups List of groups to export * \param groupList The list of groups to export
* \param thelFields List of fields to export * \param fieldList The list of fields to export
* \return New GEOM_Object, containing the created shape. * \return New GEOM_Object, containing the created shape.
*/ */
//============================================================================= //=============================================================================
bool GEOMImpl_IImportExportOperations::ExportXAO (Handle(GEOM_Object) theExportingShape, const std::string theFileName, std::list<Handle(GEOM_Object)> thelGroups, std::list<Handle(GEOM_Object)> thelFields) bool GEOMImpl_IImportExportOperations::ExportXAO(Handle(GEOM_Object) shape,
const std::string fileName,
std::list<Handle(GEOM_Object)> groupList,
std::list<Handle(GEOM_Object)> fieldList)
{ {
std::cout << ">> ExportXAO" << std::endl;
SetErrorCode(KO); SetErrorCode(KO);
bool isGood = false; bool isGood = false;
// //
//Add a new shape function with parameters // add a new shape function with parameters
Handle(GEOM_Function) aRefFunction = theExportingShape->GetLastFunction(); Handle(GEOM_Function) lastFunction = shape->GetLastFunction();
if (aRefFunction.IsNull()) return false; if (lastFunction.IsNull())
return false;
//Add a new result object // add a new result object
Handle(GEOM_Object) result = GetEngine()->AddObject(GetDocID(), GEOM_IMPORT); Handle(GEOM_Object) result = GetEngine()->AddObject(GetDocID(), GEOM_IMPORT);
//Add an Export function // add an Export function
Handle(GEOM_Function) aFunction = result->AddFunction(GEOMImpl_ExportXAODriver::GetID(), EXPORTXAO_EXPORTINGSHAPE_FILENAME_LGROUPS_LFIELDS); Handle(GEOM_Function) exportFunction = result->AddFunction(GEOMImpl_ExportXAODriver::GetID(),
if (aFunction.IsNull()) return false; EXPORTXAO_EXPORTINGSHAPE_FILENAME_LGROUPS_LFIELDS);
if (exportFunction.IsNull())
return false;
//Check if the function is set correctly // check if the function is set correctly
if (aFunction->GetDriverGUID() != GEOMImpl_ExportXAODriver::GetID()) return false; if (exportFunction->GetDriverGUID() != GEOMImpl_ExportXAODriver::GetID())
return false;
/*GEOMImpl_IExportXAO aData (aRefFunction); /*GEOMImpl_IExportXAO aData (aRefFunction);
@ -172,55 +186,109 @@ bool GEOMImpl_IImportExportOperations::ExportXAO (Handle(GEOM_Object) theExporti
SetErrorCode(aFail->GetMessageString()); SetErrorCode(aFail->GetMessageString());
return false; return false;
}*/ }*/
TCollection_AsciiString FileName = theFileName.c_str(); XAO::Xao* xaoObject = new XAO::Xao();
XAO::Xao *myXao = new XAO::Xao();
XAO::Geometry *myGeometry = new XAO::Geometry(); XAO::Geometry* geometry = new XAO::Geometry();
myGeometry->setShape(theExportingShape->GetValue()); TopoDS_Shape topoShape = shape->GetValue();
myGeometry->setName(theExportingShape->GetName()); std::ostringstream dumpStream;
Handle(TColStd_HSequenceOfTransient) subObjects = myShapesOperations->GetExistingSubObjects(theExportingShape, false); 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(); int nbSubObjects = subObjects->Length();
for (int i = 1 ; i <= nbSubObjects ; i++) { std::cout << "nb sub obj = " << nbSubObjects << std::endl;
Handle(Standard_Transient) anTransientSubObject = subObjects->Value(i); int nbVertices = 0, nbEdges = 0, nbFaces = 0, nbSolids = 0, nbGroups = 0;
if (anTransientSubObject.IsNull()) for (int i = 1; i <= nbSubObjects; i++)
{
Handle(Standard_Transient) transientSubObject = subObjects->Value(i);
if (transientSubObject.IsNull())
continue; continue;
Handle(GEOM_Object) asubObject = Handle(GEOM_Object)::DownCast(anTransientSubObject);
if (asubObject->GetType() != GEOM_GROUP) Handle(GEOM_Object) subObject = Handle(GEOM_Object)::DownCast(transientSubObject);
if (subObject->GetType() == GEOM_GROUP)
{ {
int index = myShapesOperations->GetSubShapeIndex(theExportingShape,asubObject); nbGroups++;
switch (asubObject->GetValue().ShapeType() ) }
else
{ {
case TopAbs_SOLID: switch (subObject->GetValue().ShapeType())
break; {
case TopAbs_FACE: case TopAbs_VERTEX: nbVertices++; break;
case TopAbs_EDGE: nbEdges++; break;
case TopAbs_FACE: nbFaces++; break;
case TopAbs_SOLID: nbSolids++; break;
}
}
}
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++)
{
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; break;
case TopAbs_EDGE: case TopAbs_EDGE:
geometry->setEdge(eInd++, subObject->GetName(), strIndex);
break; break;
case TopAbs_VERTEX: case TopAbs_FACE:
myGeometry->setVertexName(index,asubObject->GetName()); geometry->setFace(fInd++, subObject->GetName(), strIndex);
break;
case TopAbs_SOLID:
geometry->setSolid(sInd++, subObject->GetName(), strIndex);
break; break;
} }
} }
} }
myXao->setGeometry(myGeometry); xaoObject->setGeometry(geometry);
// Adding groups xaoObject->exportToFile(fileName.c_str());
std::list<Handle(GEOM_Object)>::iterator itG1 = thelGroups.begin();
while (itG1 != thelGroups.end()) { /*
// adding groups
std::list<Handle(GEOM_Object)>::iterator itG1 = groupList.begin();
int gInd = 0;
while (itG1 != groupList.end())
{
std::cout << "Group = " << gInd++ << std::endl;
Handle(GEOM_Object) itGroup = (*itG1++); Handle(GEOM_Object) itGroup = (*itG1++);
XAO::Group *Group = new XAO::Group(); XAO::Group* group = new XAO::Group();
Group->setName(itGroup->GetName()); group->setName(itGroup->GetName());
Handle(TColStd_HArray1OfInteger) groupIds = myGroupOperations->GetObjects(itGroup); Handle(TColStd_HArray1OfInteger) groupIds = m_groupOperations->GetObjects(itGroup);
TopAbs_ShapeEnum shapeGroup = myGroupOperations->GetType(itGroup); TopAbs_ShapeEnum shapeGroup = m_groupOperations->GetType(itGroup);
std::cout << "GroupShape = " << shapeGroup << std::endl;
if (shapeGroup == TopAbs_VERTEX) if (shapeGroup == TopAbs_VERTEX)
{ {
Group->setType(0); group->setDimension(0);
for (int i = 1; i <= groupIds->Length(); i++) for (int i = 1; i <= groupIds->Length(); i++)
{ {
int index = myGeometry->findVertex(groupIds->Value(i)); const char* index = geometry->getVertexReference(groupIds->Value(i));
Group->addValue(index); group->addElement(index);
} }
} }
myXao->addGroup(Group); xaoObject->addGroup(group);
/*{ /*{
case TopAbs_SOLID: case TopAbs_SOLID:
Group->setType(3); Group->setType(3);
@ -234,28 +302,30 @@ bool GEOMImpl_IImportExportOperations::ExportXAO (Handle(GEOM_Object) theExporti
case TopAbs_VERTEX: case TopAbs_VERTEX:
Group->setType(0); Group->setType(0);
break; break;
} *
}*/ }*/
/*
} // make a Python command
TCollection_AsciiString fileNameStr = fileName.c_str();
GEOM::TPythonDump pd(exportFunction);
//Make a Python command std::list<Handle(GEOM_Object)>::iterator itG = groupList.begin();
GEOM::TPythonDump pd (aFunction); std::list<Handle(GEOM_Object)>::iterator itF = fieldList.begin();
std::list<Handle(GEOM_Object)>::iterator itG = thelGroups.begin(); //pd << /*isGood <<**" = geompy.ExportXAO(" << shape << ", " << fileNameStr.ToCString() << ", [";
std::list<Handle(GEOM_Object)>::iterator itF = thelFields.begin();
pd << /*isGood <<*/ " = geompy.ExportXAO(" << theExportingShape << ", " << FileName.ToCString() << ", [";
pd << (*itG++); pd << (*itG++);
while (itG != thelGroups.end()) { while (itG != groupList.end())
{
pd << ", " << (*itG++); pd << ", " << (*itG++);
} }
pd << "], ["; pd << "], [";
pd << (*itF++); pd << (*itF++);
while (itF != thelFields.end()) { while (itF != fieldList.end())
{
pd << ", " << (*itF++); pd << ", " << (*itF++);
} }
pd << "])"; pd << "])";*/
SetErrorCode(OK); SetErrorCode(OK);

View File

@ -40,7 +40,8 @@ class GEOMImpl_IHealingOperations;*/
class GEOMImpl_IShapesOperations; class GEOMImpl_IShapesOperations;
class GEOMImpl_IGroupOperations; class GEOMImpl_IGroupOperations;
class GEOMImpl_IImportExportOperations: public GEOM_IOperations { class GEOMImpl_IImportExportOperations: public GEOM_IOperations
{
private: private:
/*GEOMImpl_IBasicOperations* myBasicOperations; /*GEOMImpl_IBasicOperations* myBasicOperations;
@ -51,14 +52,17 @@ private:
GEOMImpl_I3DPrimOperations* my3DPrimOperations; GEOMImpl_I3DPrimOperations* my3DPrimOperations;
GEOMImpl_ILocalOperations* myLocalOperations; GEOMImpl_ILocalOperations* myLocalOperations;
GEOMImpl_IHealingOperations* myHealingOperations;*/ GEOMImpl_IHealingOperations* myHealingOperations;*/
GEOMImpl_IShapesOperations* myShapesOperations; GEOMImpl_IShapesOperations* m_shapesOperations;
GEOMImpl_IGroupOperations* myGroupOperations; GEOMImpl_IGroupOperations* m_groupOperations;
public: public:
Standard_EXPORT GEOMImpl_IImportExportOperations(GEOM_Engine* theEngine, int theDocID); Standard_EXPORT GEOMImpl_IImportExportOperations(GEOM_Engine* engine, int docID);
Standard_EXPORT ~GEOMImpl_IImportExportOperations(); Standard_EXPORT ~GEOMImpl_IImportExportOperations();
Standard_EXPORT bool ExportXAO (Handle(GEOM_Object) theExportingShape, const std::string theFileName, std::list<Handle(GEOM_Object)> thelGroups, std::list<Handle(GEOM_Object)> thelFields); Standard_EXPORT bool ExportXAO (Handle(GEOM_Object) shape,
const std::string fileName,
std::list<Handle(GEOM_Object)> groupList,
std::list<Handle(GEOM_Object)> fieldList);
/*@@ insert new functions before this line @@ do not remove this line @@*/ /*@@ insert new functions before this line @@ do not remove this line @@*/
}; };
#endif #endif

View File

@ -242,6 +242,7 @@ libGEOMimpl_la_CPPFLAGS = \
$(KERNEL_CXXFLAGS) \ $(KERNEL_CXXFLAGS) \
$(BOOST_CPPFLAGS) \ $(BOOST_CPPFLAGS) \
$(PYTHON_INCLUDES) \ $(PYTHON_INCLUDES) \
$(LIBXML_INCLUDES) \
-I$(srcdir)/../ShHealOper \ -I$(srcdir)/../ShHealOper \
-I$(srcdir)/../NMTDS \ -I$(srcdir)/../NMTDS \
-I$(srcdir)/../NMTTools \ -I$(srcdir)/../NMTTools \

View File

@ -41,7 +41,8 @@
// function : ImportExportGUI() // function : ImportExportGUI()
// purpose : Constructor // purpose : Constructor
//======================================================================= //=======================================================================
ImportExportGUI::ImportExportGUI( GeometryGUI* parent ) : GEOMGUI( parent ) ImportExportGUI::ImportExportGUI(GeometryGUI* parent) :
GEOMGUI(parent)
{ {
} }
@ -57,28 +58,28 @@ ImportExportGUI::~ImportExportGUI()
// function : OnGUIEvent() // function : OnGUIEvent()
// purpose : // purpose :
//======================================================================= //=======================================================================
bool ImportExportGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent ) bool ImportExportGUI::OnGUIEvent(int commandId, SUIT_Desktop* parent)
{ {
SalomeApp_Application* app = getGeometryGUI()->getApp(); SalomeApp_Application* app = getGeometryGUI()->getApp();
if (!app) return false; if (!app) return false;
getGeometryGUI()->EmitSignalDeactivateDialog(); getGeometryGUI()->EmitSignalDeactivateDialog();
QDialog* aDlg = NULL;
switch ( theCommandID ) { QDialog* dialog = NULL;
switch (commandId)
{
case GEOMOp::OpExportXAO: case GEOMOp::OpExportXAO:
cout << "test" << endl; dialog = new ImportExportGUI_ExportXAODlg(getGeometryGUI(), parent);
aDlg = new ImportExportGUI_ExportXAODlg( getGeometryGUI(), parent );
break; break;
//@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@// //@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@//
default: default:
app->putInfo( tr( "GEOM_PRP_COMMAND" ).arg( theCommandID ) ); app->putInfo(tr("GEOM_PRP_COMMAND").arg(commandId));
break; break;
} }
if ( aDlg != NULL ) if (dialog != NULL)
aDlg->show(); dialog->show();
return true; return true;
} }

View File

@ -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 // This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public // modify it under the terms of the GNU Lesser General Public
@ -32,10 +32,10 @@
class ImportExportGUI: public GEOMGUI class ImportExportGUI: public GEOMGUI
{ {
public: public:
ImportExportGUI( GeometryGUI* ); ImportExportGUI(GeometryGUI* parent);
~ImportExportGUI(); ~ImportExportGUI();
bool OnGUIEvent( int, SUIT_Desktop* ); bool OnGUIEvent(int commandId, SUIT_Desktop* parent);
}; };
#endif // IMPORTEXPORTGUI_H #endif // IMPORTEXPORTGUI_H

View File

@ -1,7 +1,4 @@
// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE // Copyright (C) 2013 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
// //
// This library is free software; you can redistribute it and/or // This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public // 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 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#include "ImportExportGUI_ExportXAODlg.h"
//#include "ImportExportGUI_Widgets.h"
#include <DlgRef.h> #include <DlgRef.h>
#include <GeometryGUI.h> #include <GeometryGUI.h>
#include <GEOMBase.h> #include <GEOMBase.h>
@ -47,14 +41,17 @@
#include <TopTools_IndexedMapOfShape.hxx> #include <TopTools_IndexedMapOfShape.hxx>
#include <GEOMImpl_Types.hxx> #include <GEOMImpl_Types.hxx>
#include "ImportExportGUI_ExportXAODlg.h"
//#include "ImportExportGUI_Widgets.h"
//================================================================================= //=================================================================================
// Constructor // Constructor
//================================================================================= //=================================================================================
ImportExportGUI_ExportXAODlg::ImportExportGUI_ExportXAODlg (GeometryGUI* theGeometryGUI, QWidget* parent) ImportExportGUI_ExportXAODlg::ImportExportGUI_ExportXAODlg(GeometryGUI* geometryGUI, QWidget* parent)
: GEOMBase_Skeleton(theGeometryGUI, parent, false) :
GEOMBase_Skeleton(geometryGUI, parent, false)
{ {
myMainObj = GEOM::GEOM_Object::_nil(); m_mainObj = GEOM::GEOM_Object::_nil();
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
QPixmap imageOp(resMgr->loadPixmap("GEOM", tr("ICON_DLG_EXPORTXAO_EXPORTINGSHAPE_FILENAME_LGROUPS_LFIELDS"))); QPixmap imageOp(resMgr->loadPixmap("GEOM", tr("ICON_DLG_EXPORTXAO_EXPORTINGSHAPE_FILENAME_LGROUPS_LFIELDS")));
@ -70,10 +67,9 @@ ImportExportGUI_ExportXAODlg::ImportExportGUI_ExportXAODlg (GeometryGUI* theGeom
mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose); mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
mainFrame()->RadioButton3->close(); mainFrame()->RadioButton3->close();
QGroupBox* gbxExport = new QGroupBox(parent);
QGroupBox *GroupBoxExport = new QGroupBox(parent); QGridLayout *gridLayoutExport = new QGridLayout(gbxExport);
QGridLayout *gridLayoutExport = new QGridLayout(GroupBoxExport);
#ifndef Q_OS_MAC #ifndef Q_OS_MAC
gridLayoutExport->setSpacing(6); gridLayoutExport->setSpacing(6);
#endif #endif
@ -83,41 +79,41 @@ ImportExportGUI_ExportXAODlg::ImportExportGUI_ExportXAODlg (GeometryGUI* theGeom
gridLayoutExport->setObjectName(QString::fromUtf8("gridLayoutExport")); gridLayoutExport->setObjectName(QString::fromUtf8("gridLayoutExport"));
//**************************** //****************************
QLabel *TextLabel1 = new QLabel(tr( "GEOM_EXPORTXAO_EXPORTINGSHAPE" ),GroupBoxExport); QLabel* txtLabel1 = new QLabel(tr("GEOM_EXPORTXAO_EXPORTINGSHAPE"), gbxExport);
gridLayoutExport->addWidget(TextLabel1, 0, 0, 1, 1); gridLayoutExport->addWidget(txtLabel1, 0, 0, 1, 1);
mySelBtn = new QPushButton(GroupBoxExport); btnSelect = new QPushButton(gbxExport);
mySelBtn->setIcon(iconSelect); btnSelect->setIcon(iconSelect);
gridLayoutExport->addWidget(mySelBtn, 0, 1, 1, 1); gridLayoutExport->addWidget(btnSelect, 0, 1, 1, 1);
myMainShape = new QLineEdit(GroupBoxExport); ledShape = new QLineEdit(gbxExport);
myMainShape->setMinimumSize(QSize(100, 0)); ledShape->setMinimumSize(QSize(100, 0));
gridLayoutExport->addWidget(myMainShape, 0, 2, 1, 1); gridLayoutExport->addWidget(ledShape, 0, 2, 1, 1);
//**************************** //****************************
QLabel *TextLabel2 = new QLabel(tr( "GEOM_EXPORTXAO_FILENAME" ),GroupBoxExport); QLabel* txtLabel2 = new QLabel(tr("GEOM_EXPORTXAO_FILENAME"), gbxExport);
gridLayoutExport->addWidget(TextLabel2, 1, 0, 1, 1); gridLayoutExport->addWidget(txtLabel2, 1, 0, 1, 1);
myMainFile = new QLineEdit(GroupBoxExport); ledFileName = new QLineEdit(gbxExport);
gridLayoutExport->addWidget(myMainFile, 1, 1, 1, 2); gridLayoutExport->addWidget(ledFileName, 1, 1, 1, 2);
//**************************** //****************************
QLabel *TextLabel3 = new QLabel(tr( "GEOM_EXPORTXAO_LGROUPS" ),GroupBoxExport); QLabel* txtLabel3 = new QLabel(tr("GEOM_EXPORTXAO_LGROUPS"), gbxExport);
gridLayoutExport->addWidget(TextLabel3, 2, 0, 1, 2); gridLayoutExport->addWidget(txtLabel3, 2, 0, 1, 2);
myListGroups = new QListWidget(GroupBoxExport); lstGroups = new QListWidget(gbxExport);
gridLayoutExport->addWidget(myListGroups, 3, 0, 1, 2); gridLayoutExport->addWidget(lstGroups, 3, 0, 1, 2);
QLabel *TextLabel4 = new QLabel(tr( "GEOM_EXPORTXAO_LFIELDS" ),GroupBoxExport); QLabel* txtLabel4 = new QLabel(tr("GEOM_EXPORTXAO_LFIELDS"), gbxExport);
gridLayoutExport->addWidget(TextLabel4, 2, 2, 1, 1); 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()); QVBoxLayout* layout = new QVBoxLayout(centralWidget());
layout->setMargin(0); layout->setSpacing(6); layout->setMargin(0);
layout->addWidget(GroupBoxExport); layout->setSpacing(6);
layout->addWidget(gbxExport);
//QWidget::setTabOrder(PushButton1, LineEdit1); //QWidget::setTabOrder(PushButton1, LineEdit1);
//QWidget::setTabOrder(LineEdit1, LineEdit2); //QWidget::setTabOrder(LineEdit1, LineEdit2);
@ -142,14 +138,14 @@ ImportExportGUI_ExportXAODlg::~ImportExportGUI_ExportXAODlg()
void ImportExportGUI_ExportXAODlg::Init() void ImportExportGUI_ExportXAODlg::Init()
{ {
// Get setting of step value from file configuration // Get setting of step value from file configuration
myGroups.clear(); m_groups.clear();
myFields.clear(); m_fields.clear();
// Signal/slot connections // Signal/slot connections
connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk())); connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply())); connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
connect( mySelBtn, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); connect(btnSelect, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
connect(((SalomeApp_Application*) (SUIT_Session::session()->activeApplication()))->selectionMgr(), connect(((SalomeApp_Application*) (SUIT_Session::session()->activeApplication()))->selectionMgr(),
SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())); SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
@ -163,18 +159,20 @@ void ImportExportGUI_ExportXAODlg::Init()
//================================================================================= //=================================================================================
void ImportExportGUI_ExportXAODlg::processObject() void ImportExportGUI_ExportXAODlg::processObject()
{ {
if ( myMainObj->_is_nil() ) { if (m_mainObj->_is_nil())
myMainShape->setText( "" ); {
myMainFile->setText( "" ); ledShape->setText("");
ledFileName->setText("");
} }
else { else
myMainShape->setText( GEOMBase::GetName( myMainObj ) ); {
ledShape->setText(GEOMBase::GetName(m_mainObj));
GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations(getStudyId()); GEOM::GEOM_IShapesOperations_var aShOp = getGeomEngine()->GetIShapesOperations(getStudyId());
GEOM::ListOfGO_var Groups = aShOp->GetExistingSubObjects(myMainObj, true); GEOM::ListOfGO_var Groups = aShOp->GetExistingSubObjects(m_mainObj, true);
// Affichage des noms des groupes // Affichage des noms des groupes
for (int i = 0, n = Groups->length(); i < n; i++) for (int i = 0, n = Groups->length(); i < n; i++)
{ {
myListGroups->addItem( GEOMBase::GetName( Groups[i] ) ); lstGroups->addItem(GEOMBase::GetName(Groups[i]));
} }
} }
} }
@ -209,18 +207,19 @@ bool ImportExportGUI_ExportXAODlg::ClickOnApply()
//================================================================================= //=================================================================================
void ImportExportGUI_ExportXAODlg::SelectionIntoArgument() void ImportExportGUI_ExportXAODlg::SelectionIntoArgument()
{ {
myMainObj = GEOM::GEOM_Object::_nil(); m_mainObj = GEOM::GEOM_Object::_nil();
LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); LightApp_SelectionMgr* selMgr = myGeomGUI->getApp()->selectionMgr();
SALOME_ListIO aSelList; SALOME_ListIO selList;
aSelMgr->selectedObjects(aSelList); selMgr->selectedObjects(selList);
if (aSelList.Extent() != 1) { if (selList.Extent() != 1)
{
processObject(); processObject();
return; 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() ) { /*if ( aSelectedObject->_is_nil() ) {
processObject(); processObject();
@ -228,7 +227,6 @@ void ImportExportGUI_ExportXAODlg::SelectionIntoArgument()
}*/ }*/
//myMainObj = aSelectedObject; //myMainObj = aSelectedObject;
processObject(); processObject();
} }
@ -238,8 +236,8 @@ void ImportExportGUI_ExportXAODlg::SelectionIntoArgument()
//================================================================================= //=================================================================================
void ImportExportGUI_ExportXAODlg::SetEditCurrentArgument() void ImportExportGUI_ExportXAODlg::SetEditCurrentArgument()
{ {
myMainShape->setFocus(); ledShape->setFocus();
myEditCurrentArgument = myMainShape; myEditCurrentArgument = ledShape;
SelectionIntoArgument(); SelectionIntoArgument();
} }
//================================================================================= //=================================================================================
@ -291,23 +289,27 @@ bool ImportExportGUI_ExportXAODlg::execute (ObjectList& objects)
{ {
bool res = false; bool res = false;
GEOM::GEOM_Object_var anObj; GEOM::GEOM_Object_var obj;
GEOM::GEOM_IImportExportOperations_var anOper = GEOM::GEOM_IImportExportOperations::_narrow(getOperation()); GEOM::GEOM_IImportExportOperations_var ieOp = GEOM::GEOM_IImportExportOperations::_narrow(getOperation());
GEOM::GEOM_IShapesOperations_var anShapesOper = getGeomEngine()->GetIShapesOperations(getStudyId()); GEOM::GEOM_IShapesOperations_var shapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
GEOM::ListOfGO_var mylGroups = anShapesOper->GetExistingSubObjects(myMainObj, true); GEOM::ListOfGO_var groups = shapesOp->GetExistingSubObjects(m_mainObj, true);
GEOM::ListOfGO_var mylFields = new GEOM::ListOfGO(); GEOM::ListOfGO_var fields = new GEOM::ListOfGO();
mylGroups->length( myGroups.count() ); std::cout << " == Groups" << std::endl;
for ( int i = 0; i < myGroups.count(); i++ ) groups->length(m_groups.count());
mylGroups[i] = myGroups[i].copy(); for (int i = 0; i < m_groups.count(); i++)
groups[i] = m_groups[i].copy();
mylFields->length( myFields.count() ); std::cout << " == Fields" << std::endl;
for ( int i = 0; i < myFields.count(); i++ ) fields->length(m_fields.count());
mylFields[i] = myFields[i].copy(); for (int i = 0; i < m_fields.count(); i++)
fields[i] = m_fields[i].copy();
// call engine function // call engine function
res = anOper->ExportXAO(myMainObj, myMainFile->text().toStdString().c_str(), mylGroups, mylFields); 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;
} }

View File

@ -1,7 +1,4 @@
// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE // Copyright (C) 2013 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
// //
// This library is free software; you can redistribute it and/or // This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public // modify it under the terms of the GNU Lesser General Public
@ -23,7 +20,7 @@
#define IMPORTEXPORTGUI_EXPORTXAODLG_H #define IMPORTEXPORTGUI_EXPORTXAODLG_H
#include <GEOMBase_Skeleton.h> #include <GEOMBase_Skeleton.h>
#include "GEOM_GenericObjPtr.h" #include <GEOM_GenericObjPtr.h>
class QLineEdit; class QLineEdit;
class QButtonGroup; class QButtonGroup;
@ -55,15 +52,15 @@ private:
void processObject(); void processObject();
private: private:
GEOM::GEOM_Object_var myMainObj; GEOM::GEOM_Object_var m_mainObj;
QList<GEOM::GeomObjPtr> myGroups; QList<GEOM::GeomObjPtr> m_groups;
QList<GEOM::GeomObjPtr> myFields; QList<GEOM::GeomObjPtr> m_fields;
//ImportExportGUI_1Sel1LineEdit2ListWidget* myGrp; //ImportExportGUI_1Sel1LineEdit2ListWidget* myGrp;
QLineEdit *myMainShape; QLineEdit* ledShape;
QLineEdit *myMainFile; QLineEdit* ledFileName;
QListWidget *myListGroups; QListWidget* lstGroups;
QListWidget *myListFields; QListWidget* lstFields;
QPushButton *mySelBtn; QPushButton* btnSelect;
private slots: private slots:
void ClickOnOk(); void ClickOnOk();

View File

@ -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 // This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public // modify it under the terms of the GNU Lesser General Public

View File

@ -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 // This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public // modify it under the terms of the GNU Lesser General Public

View File

@ -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 <Utils_SALOME_Exception.hxx>
#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);
}

View File

@ -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 <string>
#include <map>
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<int, GeometricElement> m_elements;
};
}
#endif /* __XAO_GEOMETRICELEMENT_HXX__ */

View File

@ -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 // This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public // modify it under the terms of the GNU Lesser General Public
@ -18,6 +18,7 @@
// //
// Author : Nathalie Gore (OpenCascade) // Author : Nathalie Gore (OpenCascade)
#include "XaoUtils.hxx"
#include "Geometry.hxx" #include "Geometry.hxx"
#include <Standard_TypeMismatch.hxx> #include <Standard_TypeMismatch.hxx>
@ -29,7 +30,7 @@
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <iostream> #include <iostream>
#include <ostream> #include <iosfwd>
#include <list> #include <list>
#include <TopTools_MapOfShape.hxx> #include <TopTools_MapOfShape.hxx>
@ -42,57 +43,20 @@
#include <TColStd_HArray1OfInteger.hxx> #include <TColStd_HArray1OfInteger.hxx>
#include <TColStd_HSequenceOfInteger.hxx> #include <TColStd_HSequenceOfInteger.hxx>
using namespace std;
using namespace XAO; using namespace XAO;
Geometry::Geometry() Geometry::Geometry()
{ {
_myFormat = "BREP"; m_format = "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;
} }
Geometry::~Geometry() 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; m_shape = shape;
// intialization of Ids // intialization of Ids
initListIds(TopAbs_VERTEX); initListIds(TopAbs_VERTEX);
@ -103,9 +67,9 @@ void Geometry::setShape(TopoDS_Shape Shape)
void Geometry::setShape(const char* brep) void Geometry::setShape(const char* brep)
{ {
istringstream streamBrep(brep); std::istringstream streamBrep(brep);
BRep_Builder aBuilder; BRep_Builder builder;
BRepTools::Read(_myShape, streamBrep, aBuilder); BRepTools::Read(m_shape, streamBrep, builder);
// intialization of Ids // intialization of Ids
initListIds(TopAbs_VERTEX); initListIds(TopAbs_VERTEX);
@ -116,132 +80,116 @@ void Geometry::setShape(const char * brep )
const char* Geometry::getBREP() const char* Geometry::getBREP()
{ {
ostringstream streamShape; std::ostringstream streamShape;
BRepTools::Write(_myShape, streamShape); BRepTools::Write(m_shape, streamShape);
return streamShape.str().c_str(); 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) if (m_nbVertices == 0)
Standard_TypeMismatch::Raise("Problem with number of vertices"); Standard_TypeMismatch::Raise("Problem with number of vertices");
if (_myNamesVertices == NULL) if (m_verticesNames == NULL)
_myNamesVertices = new std::string[_myNbVertices]; m_verticesNames = new std::string[m_nbVertices];
_myNamesVertices[index] = myName;
}
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); int index = findVertex(id);
if (index == -1) if (index == -1)
Standard_TypeMismatch::Raise("Problem with the id of the vertex"); Standard_TypeMismatch::Raise("Problem with the id of the vertex");
_myNamesVertices[index] = myName; m_verticesNames[index] = name;
} }
const char* Geometry::findVertexName(int id) const char* Geometry::findVertexName(int id)
{ {
if (_myNbVertices == 0) { if (m_nbVertices == 0)
{
Standard_TypeMismatch::Raise("Problem with number of vertices"); Standard_TypeMismatch::Raise("Problem with number of vertices");
return ""; return "";
} }
int index = findVertex(id); int index = findVertex(id);
if (index == -1) { if (index == -1)
{
Standard_TypeMismatch::Raise("Problem with the id of the vertex"); Standard_TypeMismatch::Raise("Problem with the id of the vertex");
return ""; return "";
} }
return _myNamesVertices[index].c_str(); return m_verticesNames[index].c_str();
} }*/
/*
int Geometry::findVertex(int id) int Geometry::findVertex(int id)
{ {
int index = -1; int index = -1;
for (int i = 0, n = _myNbVertices; i < n; i++) for (int i = 0, n = m_nbVertices; i < n; i++)
{ {
if (_myIdsVertices[i] == id) if (m_verticesIds[i] == id)
return i; return i;
} }
return index; return index;
} }*/
void Geometry::initListIds(const Standard_Integer theShapeType) void Geometry::initListIds(const Standard_Integer shapeType)
{ {
std::list<int> aList;
TopTools_MapOfShape mapShape; TopTools_MapOfShape mapShape;
TopTools_ListOfShape listShape; TopTools_ListOfShape listShape;
TopExp_Explorer exp (_myShape, TopAbs_ShapeEnum(theShapeType)); TopExp_Explorer exp(m_shape, TopAbs_ShapeEnum(shapeType));
for (; exp.More(); exp.Next()) for (; exp.More(); exp.Next())
{
if (mapShape.Add(exp.Current())) if (mapShape.Add(exp.Current()))
listShape.Append(exp.Current()); listShape.Append(exp.Current());
}
if (listShape.IsEmpty()) { if (listShape.IsEmpty())
{
return; return;
} }
TopTools_IndexedMapOfShape anIndices; TopTools_IndexedMapOfShape anIndices;
TopExp::MapShapes(_myShape, anIndices); TopExp::MapShapes(m_shape, anIndices);
Handle(TColStd_HArray1OfInteger) anArray; //Handle (TColStd_HArray1OfInteger) anArray;
std::list<int> aList;
TopTools_ListIteratorOfListOfShape itSub(listShape); TopTools_ListIteratorOfListOfShape itSub(listShape);
for (int index = 1; itSub.More(); itSub.Next(), ++index) { for (int index = 1; itSub.More(); itSub.Next(), ++index)
TopoDS_Shape aValue = itSub.Value(); {
aList.push_back(anIndices.FindIndex(aValue)); TopoDS_Shape value = itSub.Value();
aList.push_back(anIndices.FindIndex(value));
} }
std::list<int>::iterator it = aList.begin(); std::list<int>::iterator it = aList.begin();
switch ( theShapeType ) { switch (shapeType)
{
case TopAbs_VERTEX: /* Fill vertices ids */ case TopAbs_VERTEX: /* Fill vertices ids */
{ {
_myNbVertices = aList.size(); m_vertices.setSize(aList.size());
if (_myIdsVertices != NULL)
delete _myIdsVertices;
_myIdsVertices = new int[_myNbVertices];
for (int i = 0; it != aList.end(); it++, i++) for (int i = 0; it != aList.end(); it++, i++)
_myIdsVertices[i] = (*it); m_vertices.setReference(i, XaoUtils::intToString((*it)));
break; break;
} }
case TopAbs_EDGE: /* Fill edges ids */ case TopAbs_EDGE: /* Fill edges ids */
{ {
_myNbEdges = aList.size(); m_edges.setSize(aList.size());
if (_myIdsEdges != NULL)
delete _myIdsEdges;
_myIdsEdges = new int[_myNbEdges];
for (int i = 0; it != aList.end(); it++, i++) for (int i = 0; it != aList.end(); it++, i++)
_myIdsEdges[i] = (*it); m_edges.setReference(i, XaoUtils::intToString((*it)));
break; break;
} }
case TopAbs_FACE: /* Fill faces ids */ case TopAbs_FACE: /* Fill faces ids */
{ {
_myNbFaces = aList.size(); m_faces.setSize(aList.size());
if (_myIdsFaces != NULL)
delete _myIdsFaces;
_myIdsFaces = new int[_myNbFaces];
for (int i = 0; it != aList.end(); it++, i++) for (int i = 0; it != aList.end(); it++, i++)
_myIdsFaces[i] = (*it); m_faces.setReference(i, XaoUtils::intToString((*it)));
break; break;
} }
case TopAbs_SOLID: /* Fill solids ids */ case TopAbs_SOLID: /* Fill solids ids */
{ {
_myNbSolids = aList.size(); m_solids.setSize(aList.size());
if (_myIdsSolids != NULL)
delete _myIdsSolids;
_myIdsSolids = new int[_myNbSolids];
for (int i = 0; it != aList.end(); it++, i++) for (int i = 0; it != aList.end(); it++, i++)
_myIdsSolids[i] = (*it); m_solids.setReference(i, XaoUtils::intToString((*it)));
break; break;
} }
} }

View File

@ -26,6 +26,8 @@
#include <SALOMEconfig.h> #include <SALOMEconfig.h>
#include <TopoDS_Shape.hxx> #include <TopoDS_Shape.hxx>
# include "GeometricElement.hxx"
namespace XAO namespace XAO
{ {
class Geometry class Geometry
@ -34,49 +36,85 @@ namespace XAO
Geometry(); Geometry();
~Geometry(); ~Geometry();
void setName(const char *name) { _myName=name; } const char* getName()
const char *getName() const { return _myName.c_str(); } {
return m_name.c_str();
}
void setName(const char* name)
{
m_name = name;
}
void setFormat(const char *format) { _myFormat=format; } const char* getFormat()
const char *getFormat() const { return _myFormat.c_str(); } {
return m_format.c_str();
}
void setFormat(const char* format)
{
m_format = format;
}
void setShape(TopoDS_Shape Shape); TopoDS_Shape getShape()
TopoDS_Shape getShape() { return _myShape; } {
return m_shape;
}
void setShape(TopoDS_Shape shape);
void setShape(const char * brep );
const char* getBREP(); const char* getBREP();
void setShape(const char* brep);
int countVertices() { return _myNbVertices; } int countVertices() { return m_vertices.getSize(); }
int findVertex(int id); int countEdges() { return m_edges.getSize(); }
void setVertexName(int index, const char *myName); int countFaces() { return m_faces.getSize(); }
const char * getVertexName(int index) { return _myNamesVertices[index].c_str(); } int countSolids() { return m_solids.getSize(); }
void changeVertexName(int id, const char *myName);
const char * findVertexName(int id);
int countEdges() { return _myNbEdges; } void setCountVertices(const int nb) { m_vertices.setSize(nb); }
int countFaces() { return _myNbFaces; } void setCountEdges(const int nb) { m_edges.setSize(nb); }
int countSolids() { return _myNbSolids; } 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: private:
void initListIds(const Standard_Integer theShapeType); void initListIds(const Standard_Integer shapeType);
private: private:
TopoDS_Shape _myShape; TopoDS_Shape m_shape;
std::string _myName; std::string m_name;
std::string _myFormat; std::string m_format;
int _myNbVertices; GeometricElementList m_vertices;
std::string *_myNamesVertices; GeometricElementList m_edges;
int *_myIdsVertices; GeometricElementList m_faces;
int _myNbEdges; GeometricElementList m_solids;
std::string *_myNamesEdges;
int *_myIdsEdges;
int _myNbFaces;
std::string *_myNamesFaces;
int *_myIdsFaces;
int _myNbSolids;
std::string *_myNamesSolids;
int *_myIdsSolids;
}; };
} }

View File

@ -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 // This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public // 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 // 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" #include "Group.hxx"
@ -24,12 +24,11 @@ using namespace XAO;
Group::Group() Group::Group()
{ {
_myType = 0; m_dimension = 0;
_myCount = 0; m_count = 0;
} }
Group::~Group() Group::~Group()
{ {
} }

View File

@ -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 // This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public // modify it under the terms of the GNU Lesser General Public
@ -16,13 +16,13 @@
// //
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // 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__ #ifndef __XAO_GROUP_HXX__
#define __XAO_GROUP_HXX__ #define __XAO_GROUP_HXX__
#include <string> #include <string>
#include <list> #include <vector>
namespace XAO namespace XAO
{ {
@ -32,25 +32,44 @@ namespace XAO
Group(); Group();
~Group(); ~Group();
void setName(const char *name) { _myName=name; } void setName(const char* name)
const char *getName() const { return _myName.c_str(); } {
m_name = name;
}
const char *getName() const
{
return m_name.c_str();
}
void setType(int type) { _myType=type; } void setDimension(int dimension)
int getType() { return _myType; } {
m_dimension = dimension;
}
int getDimension()
{
return m_dimension;
}
int getCount() { return _myValues.size(); } int getCount()
{
return m_elements.size();
}
void addValue(int value) {_myValues.push_back(value);} void addElement(const char* value)
//int getValue(int index) { return _myValues[index]; } {
m_elements.push_back(value);
}
const char* getElement(const int index)
{
return m_elements[index].c_str();
}
private: private:
void sort() {_myValues.sort();} std::string m_name;
int m_dimension;
private: int m_count;
std::string _myName; std::vector<std::string> m_elements;
int _myType;
int _myCount;
std::list<int> _myValues;
}; };
} }

View File

@ -21,7 +21,9 @@
# #
include $(top_srcdir)/adm_local/unix/make_common_starter.am include $(top_srcdir)/adm_local/unix/make_common_starter.am
if CPPUNIT_IS_OK
SUBDIRS = . tests
endif
# =============================================================== # ===============================================================
# Files to be installed # Files to be installed
@ -29,6 +31,8 @@ include $(top_srcdir)/adm_local/unix/make_common_starter.am
# #
# header files # header files
salomeinclude_HEADERS = \ salomeinclude_HEADERS = \
XaoUtils.hxx \
GeometricElement.hxx \
Xao.hxx \ Xao.hxx \
Geometry.hxx \ Geometry.hxx \
Group.hxx \ Group.hxx \
@ -36,13 +40,14 @@ salomeinclude_HEADERS = \
lib_LTLIBRARIES = libXAO.la lib_LTLIBRARIES = libXAO.la
dist_libXAO_la_SOURCES = \ dist_libXAO_la_SOURCES = \
XaoUtils.cxx \
GeometricElement.cxx \
Xao.cxx \ Xao.cxx \
Geometry.cxx \ Geometry.cxx \
Group.cxx \ Group.cxx \
Field.cxx Field.cxx
libXAO_la_CPPFLAGS = \ libXAO_la_CPPFLAGS = \
$(GEOM_CXXFLAGS) \ $(GEOM_CXXFLAGS) \
$(CAS_CPPFLAGS) \ $(CAS_CPPFLAGS) \

View File

@ -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 // This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public // 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 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
// //
// Author : Nathalie Gore (OpenCascade) // Author : Nathalie Gore (OpenCascade), Frederic Pons (OpenCascade)
#include <libxml/parser.h>
#include "XaoUtils.hxx"
#include "Xao.hxx" #include "Xao.hxx"
#include "Geometry.hxx" #include "Geometry.hxx"
#include "Group.hxx" #include "Group.hxx"
#include "Field.hxx" #include "Field.hxx"
#include <Utils_SALOME_Exception.hxx>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
#include <fstream>
#include <sstream>
#include <iostream>
#include <ostream>
using namespace XAO; 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() Xao::Xao()
{ {
_myAuthor = "Nathalie Gore"; m_author = "";
_myVersion = "1.0"; m_version = (char*)C_XAO_VERSION;
_myGeometry = NULL; m_geometry = NULL;
_myNbGroups = 0; m_nbGroups = 0;
} }
Xao::Xao(const char* author, const char* version) Xao::Xao(const char* author, const char* version)
{ {
_myAuthor = author; m_author = author;
_myVersion = version; m_version = version;
_myGeometry = NULL; m_geometry = NULL;
_myNbGroups = 0; m_nbGroups = 0;
} }
Xao::~Xao() Xao::~Xao()
{ {
if (_myGeometry != NULL) if (m_geometry != NULL)
{ {
delete _myGeometry; delete m_geometry;
_myGeometry = NULL; m_geometry = NULL;
}
// for (std::list<Group*>::iterator it = m_groups.begin(); it != m_groups.end(); ++it)
// {
// delete (*it);
// }
}
Group* Xao::getGroup(const int index)
{
int i = 0;
for (std::list<Group*>::iterator it = m_groups.begin(); it != m_groups.end(); ++it, ++i)
{
if (i == index)
return (*it);
} }
} }
bool Xao::Export(const char* fileName)
bool Xao::exportToFile(const char* fileName)
{ {
if (_myGeometry == NULL) xmlDocPtr doc = exportXMLDoc();
return false; xmlSaveFormatFileEnc(fileName, doc, "UTF-8", 2);
xmlFreeDoc(doc);
xmlDocPtr master_doc = 0; return true;
xmlNodePtr xao_node = 0; }
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 // Creating the Xml document
master_doc = xmlNewDoc(BAD_CAST "1.0"); xmlDocPtr masterDocument = xmlNewDoc(BAD_CAST "1.0");
xao_node = xmlNewNode(0, BAD_CAST "XAO"); xmlNodePtr xao = xmlNewNode(0, C_TAG_XAO);
xmlDocSetRootElement(master_doc,xao_node); xmlDocSetRootElement(masterDocument, xao);
xmlNodePtr version_node = xmlNewChild(xao_node,0, BAD_CAST "version", BAD_CAST _myVersion.c_str()); xmlNewProp(xao, C_ATTR_XAO_VERSION, BAD_CAST getVersion());
xmlNodePtr author_node = xmlNewChild(xao_node,0, BAD_CAST "author", BAD_CAST _myAuthor.c_str()); 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 // Geometric part
xmlNodePtr geom_node = xmlNewChild(xao_node,0, BAD_CAST "geometry",0); xmlNodePtr geometry = xmlNewChild(xao, 0, C_TAG_GEOMETRY, 0);
xmlNodePtr name_geom_node = xmlNewChild(geom_node,0, BAD_CAST "name",BAD_CAST _myGeometry->getName()); xmlNewProp(geometry, C_ATTR_GEOMETRY_NAME, BAD_CAST m_geometry->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); xmlNodePtr shape = xmlNewChild(geometry, 0, C_TAG_SHAPE, 0);
ostringstream stream; xmlNewProp(shape, C_ATTR_SHAPE_FORMAT, BAD_CAST m_geometry->getFormat());
stream << _myGeometry->countVertices(); const char* brep = m_geometry->getBREP();
xmlNodePtr count_topo_geom_node = xmlNewChild(count_topo_geom_node,0, BAD_CAST "topology", BAD_CAST stream.str().c_str());*/ 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<Group*>::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);
}
}
}

View File

@ -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 // This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public // modify it under the terms of the GNU Lesser General Public
@ -16,17 +16,19 @@
// //
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // 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__ #ifndef __XAO_XAO_HXX__
#define __XAO_XAO_HXX__ #define __XAO_XAO_HXX__
#include <string> #include <string>
#include <list> #include <list>
#include <libxml/parser.h>
namespace XAO namespace XAO
{ {
enum Kind{ enum Kind
{
VERTEX, VERTEX,
EDGE, EDGE,
FACE, FACE,
@ -44,33 +46,54 @@ namespace XAO
Xao(const char* author, const char* version); Xao(const char* author, const char* version);
~Xao(); ~Xao();
void setAuthor(const char *author) { _myAuthor=author; } void setAuthor(const char* author) { m_author = author; }
const char *getAuthor() const { return _myAuthor.c_str(); } const char* getAuthor() { return m_author.c_str(); }
void setVersion(const char *version) { _myVersion=version; } void setVersion(const char* version) { m_version = version; }
const char *getVersion() const { return _myVersion.c_str(); } const char* getVersion() { return m_version.c_str(); }
void setGeometry(Geometry *myGeometry) { _myGeometry=myGeometry; } void setGeometry(Geometry* geometry) { m_geometry = geometry; }
const Geometry *getGeometry() const { return _myGeometry; } Geometry* getGeometry() { return m_geometry; }
int getNbGroups() { return _myGroups.size(); } int countGroups() { return m_groups.size(); }
void addGroup(Group *myGroup) { _myGroups.push_back(myGroup); } Group* getGroup(const int index);
void removeGroup(Group *myGroup) { _myGroups.remove(myGroup); } void addGroup(Group* group) { m_groups.push_back(group); }
void removeGroup(Group* group) { m_groups.remove(group); }
int getNbFields() { return _myNbFields; } bool exportToFile(const char* fileName);
const char* getXML();
bool Export(const char* fileName); bool importFromFile(const char* fileName);
bool setXML(const char* xml);
private: private:
std::string _myAuthor; std::string m_author;
std::string _myVersion; std::string m_version;
Geometry *_myGeometry; Geometry* m_geometry;
int _myNbGroups; int m_nbGroups;
std::list<Group *> _myGroups; std::list<Group*> m_groups;
int _myNbFields; //int m_nbFields;
//std::list<Field *> _myFields; //std::list<Field*> 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 #endif

61
src/XAO/XaoUtils.cxx Normal file
View File

@ -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 <cstring>
#include <sstream>
#include <iosfwd>
#include <Utils_SALOME_Exception.hxx>
#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");
}

37
src/XAO/XaoUtils.hxx Normal file
View File

@ -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__ */

View File

@ -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 <stdio.h>
#include <Utils_SALOME_Exception.hxx>
#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);
}

View File

@ -0,0 +1,31 @@
#ifndef __BUILDING_IMPORT_TEST_HXX__
#define __BUILDING_IMPORT_TEST_HXX__
#include <cppunit/extensions/HelperMacros.h>
#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

161
src/XAO/tests/MainTest.hxx Normal file
View File

@ -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 <cppunit/CompilerOutputter.h>
#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TextTestProgressListener.h>
#include <cppunit/BriefTestProgressListener.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/TestRunner.h>
#include <stdexcept>
#include <cstring>
#include <iostream>
#include <fstream>
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

32
src/XAO/tests/Makefile.am Executable file
View File

@ -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

View File

@ -0,0 +1,5 @@
#include "ImportExportTest.hxx"
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::ImportExportTest);
#include "MainTest.hxx"

321
src/XAO/tests/data/test.xao Normal file
View File

@ -0,0 +1,321 @@
<?xml version="1.0" encoding="UTF-8"?>
<XAO version="1.0" author="me">
<geometry name="mygeom">
<shape format="BREP">
<![CDATA[
DBRep_DrawableShape
CASCADE Topology V1, (c) Matra-Datavision
Locations 0
Curve2ds 24
1 0 0 1 0
1 0 0 1 0
1 200 0 0 -1
1 0 0 0 1
1 0 -200 1 0
1 0 0 1 0
1 0 0 0 -1
1 0 0 0 1
1 0 0 1 0
1 0 200 1 0
1 200 0 0 -1
1 200 0 0 1
1 0 -200 1 0
1 0 200 1 0
1 0 0 0 -1
1 200 0 0 1
1 0 0 0 1
1 0 0 1 0
1 200 0 0 1
1 0 0 1 0
1 0 0 0 1
1 0 200 1 0
1 200 0 0 1
1 0 200 1 0
Curves 12
1 0 0 0 0 0 1
1 0 0 200 -0 1 0
1 0 200 0 0 0 1
1 0 0 0 -0 1 0
1 200 0 0 0 0 1
1 200 0 200 0 1 0
1 200 200 0 0 0 1
1 200 0 0 -0 1 0
1 0 0 0 1 0 -0
1 0 0 200 1 0 -0
1 0 200 0 1 0 -0
1 0 200 200 1 0 -0
Polygon3D 0
PolygonOnTriangulations 0
Surfaces 6
1 0 0 0 1 0 -0 0 0 1 0 -1 0
1 0 0 0 -0 1 0 0 0 1 1 0 -0
1 0 0 200 0 0 1 1 0 -0 -0 1 0
1 0 200 0 -0 1 0 0 0 1 1 0 -0
1 0 0 0 0 0 1 1 0 -0 -0 1 0
1 200 0 0 1 0 -0 0 0 1 0 -1 0
Triangulations 0
TShapes 34
Ve
1e-07
0 0 200
0 0
0101101
*
Ve
1e-07
0 0 0
0 0
0101101
*
Ed
1e-07 1 1 0
1 1 0 0 200
2 1 1 0 0 200
2 2 2 0 0 200
0
0101000
-34 0 +33 0 *
Ve
1e-07
0 200 200
0 0
0101101
*
Ed
1e-07 1 1 0
1 2 0 0 200
2 3 1 0 0 200
2 4 3 0 0 200
0
0101000
-31 0 +34 0 *
Ve
1e-07
0 200 0
0 0
0101101
*
Ed
1e-07 1 1 0
1 3 0 0 200
2 5 1 0 0 200
2 6 4 0 0 200
0
0101000
-31 0 +29 0 *
Ed
1e-07 1 1 0
1 4 0 0 200
2 7 1 0 0 200
2 8 5 0 0 200
0
0101000
-29 0 +33 0 *
Wi
0101000
-32 0 -30 0 +28 0 +27 0 *
Fa
0 1e-07 1 0
0111000
+26 0 *
Ve
1e-07
200 0 200
0 0
0101101
*
Ve
1e-07
200 0 0
0 0
0101101
*
Ed
1e-07 1 1 0
1 5 0 0 200
2 9 6 0 0 200
2 10 2 0 0 200
0
0101000
-24 0 +23 0 *
Ve
1e-07
200 200 200
0 0
0101101
*
Ed
1e-07 1 1 0
1 6 0 0 200
2 11 6 0 0 200
2 12 3 0 0 200
0
0101000
-21 0 +24 0 *
Ve
1e-07
200 200 0
0 0
0101101
*
Ed
1e-07 1 1 0
1 7 0 0 200
2 13 6 0 0 200
2 14 4 0 0 200
0
0101000
-21 0 +19 0 *
Ed
1e-07 1 1 0
1 8 0 0 200
2 15 6 0 0 200
2 16 5 0 0 200
0
0101000
-19 0 +23 0 *
Wi
0101000
-22 0 -20 0 +18 0 +17 0 *
Fa
0 1e-07 6 0
0111000
+16 0 *
Ed
1e-07 1 1 0
1 9 0 0 200
2 17 2 0 0 200
2 18 5 0 0 200
0
0101000
-23 0 +33 0 *
Ed
1e-07 1 1 0
1 10 0 0 200
2 19 2 0 0 200
2 20 3 0 0 200
0
0101000
-24 0 +34 0 *
Wi
0101000
-14 0 -22 0 +13 0 +32 0 *
Fa
0 1e-07 2 0
0111000
+12 0 *
Ed
1e-07 1 1 0
1 11 0 0 200
2 21 4 0 0 200
2 22 5 0 0 200
0
0101000
-19 0 +29 0 *
Ed
1e-07 1 1 0
1 12 0 0 200
2 23 4 0 0 200
2 24 3 0 0 200
0
0101000
-21 0 +31 0 *
Wi
0101000
-10 0 -18 0 +9 0 +28 0 *
Fa
0 1e-07 4 0
0111000
+8 0 *
Wi
0101000
-27 0 -10 0 +17 0 +14 0 *
Fa
0 1e-07 5 0
0111000
+6 0 *
Wi
0101000
-30 0 -9 0 +20 0 +13 0 *
Fa
0 1e-07 3 0
0111000
+4 0 *
Sh
0101100
-25 0 +15 0 -11 0 +7 0 -5 0 +3 0 *
So
1100000
+2 0 *
+1 0
]]>
</shape>
<topology>
<vertices count="4">
<vertex index="0" name="v1" reference="1"/>
<vertex index="1" name="" reference="2"/>
<vertex index="2" name="v3" reference="3"/>
<vertex index="3" name="" reference="4"/>
</vertices>
<edges count="3">
<edge index="0" name="e1" reference="5"/>
<edge index="1" name="" reference="6"/>
<edge index="2" name="e3" reference="7"/>
</edges>
<faces count="2">
<face index="0" name="f1" reference="8"/>
<face index="1" name="" reference="9"/>
</faces>
<solids count="1">
<solid index="0" name="s1" reference="10"/>
</solids>
</topology>
</geometry>
<groups>
<group name="boite_1" dimension="solid" count="1">
<element index="1" />
</group>
<group name="" dimension="face" count="3">
<element index="5" />
<element index="8" />
<element index="9" />
</group>
</groups>
</XAO>