Merge from BR_V7_main_Field branch (02/09/2013)

This commit is contained in:
vsr 2013-10-02 13:13:33 +00:00
parent b51357b79d
commit f1519c7ef3
107 changed files with 12499 additions and 125 deletions

View File

@ -85,7 +85,7 @@ FIND_PACKAGE(SalomeSWIG REQUIRED)
FIND_PACKAGE(SalomeBoost REQUIRED)
FIND_PACKAGE(SalomeOmniORB REQUIRED)
FIND_PACKAGE(SalomeOmniORBPy REQUIRED)
#FIND_PACKAGE(SalomeLibXml2 REQUIRED)
FIND_PACKAGE(SalomeLibXml2 REQUIRED)
FIND_PACKAGE(SalomeHDF5 REQUIRED COMPONENTS C)
# Other KERNEL optionals:
@ -229,13 +229,13 @@ INCLUDE(CMakePackageConfigHelpers)
SET(_${PROJECT_NAME}_exposed_targets
GEOMArchimede BREPExport BREPImport BlockFix GEOMbasic GEOMAlgo GEOMClient GEOMImpl
GEOMUtils GEOMEngine GEOM_SupervEngine IGESExport IGESImport GEOMSketcher
SalomeIDLGEOM STEPExport STEPImport STLExport ShHealOper
SalomeIDLGEOM STEPExport STEPImport STLExport ShHealOper XAO AdvancedEngine
)
IF(SALOME_BUILD_GUI)
LIST(APPEND _${PROJECT_NAME}_exposed_targets
AdvancedGUI BasicGUI BlocksGUI BooleanGUI BuildGUI DisplayGUI DlgRef EntityGUI GEOMBase
GEOMFiltersSelection GEOM GEOMToolsGUI GenerationGUI GroupGUI Material MeasureGUI GEOMObject
OCC2VTK VTKExport OperationGUI PrimitiveGUI RepairGUI TransformationGUI
OCC2VTK VTKExport OperationGUI PrimitiveGUI RepairGUI TransformationGUI ImportExportGUI
)
ENDIF(SALOME_BUILD_GUI)

View File

@ -17,45 +17,52 @@
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
SET(GEOM_CXXFLAGS -I${GEOM_ROOT_DIR}/include/salome)
SET(GEOM_CXXFLAGS -I${GEOM_ROOT_DIR}/include/salome) # to be removed
SET(GEOM_INCLUDE_DIRS ${GEOM_ROOT_DIR}/include/salome)
FIND_LIBRARY(AdvancedEngine AdvancedEngine ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(AdvancedGUI AdvancedGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(BasicGUI BasicGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(BlocksGUI BlocksGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(BooleanGUI BooleanGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(BREPExport BREPExport ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(BREPImport BREPImport ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(BuildGUI BuildGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(DisplayGUI DisplayGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(DlgRef DlgRef ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(EntityGUI EntityGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GenerationGUI GenerationGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOMAlgo GEOMAlgo ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOMArchimede GEOMArchimede ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOMBase GEOMBase ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOMbasic GEOMbasic ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOMClient GEOMClient ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOMEngine GEOMEngine ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOMFiltersSelection GEOMFiltersSelection ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOMimpl GEOMimpl ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOMObject GEOMObject ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOMSketcher GEOMSketcher ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM GEOM ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_GEOMArchimede GEOMArchimede ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_BREPExport BREPExport ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_BREPImport BREPImport ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_BlockFix BlockFix ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_GEOMbasic GEOMbasic ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_GEOMAlgo GEOMAlgo ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_GEOMClient GEOMClient ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_GEOMimpl GEOMimpl ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_GEOMUtils GEOMUtils ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_GEOMEngine GEOMEngine ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_SupervEngine GEOM_SupervEngine ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOMToolsGUI GEOMToolsGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GroupGUI GroupGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(IGESExport IGESExport ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(IGESImport IGESImport ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(MeasureGUI MeasureGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(OCC2VTK OCC2VTK ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(OperationGUI OperationGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(PrimitiveGUI PrimitiveGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(RepairGUI RepairGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(SalomeIDLGEOM SalomeIDLGEOM ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(ShHealOper ShHealOper ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(STEPExport STEPExport ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(STEPImport STEPImport ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(STLExport STLExport ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(TransformationGUI TransformationGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(VTKExport VTKExport ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_IGESExport IGESExport ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_IGESImport IGESImport ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_GEOMSketcher GEOMSketcher ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_SalomeIDLGEOM SalomeIDLGEOM ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_STEPExport STEPExport ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_STEPImport STEPImport ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_STLExport STLExport ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_ShHealOper ShHealOper ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_XAO XAO ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_AdvancedEngine AdvancedEngine ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_AdvancedGUI AdvancedGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_BasicGUI BasicGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_BlocksGUI BlocksGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_BooleanGUI BooleanGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_BuildGUI BuildGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_DisplayGUI DisplayGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_DlgRef DlgRef ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_EntityGUI EntityGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_GEOMBase GEOMBase ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_GEOMFiltersSelection GEOMFiltersSelection ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_GEOM GEOM ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_GEOMToolsGUI GEOMToolsGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_GenerationGUI GenerationGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_GroupGUI GroupGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_Material Material ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_MeasureGUI MeasureGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_GEOMObject GEOMObject ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_OCC2VTK OCC2VTK ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_VTKExport VTKExport ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_OperationGUI OperationGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_PrimitiveGUI PrimitiveGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_RepairGUI RepairGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_TransformationGUI TransformationGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_ImportExportGUI ImportExportGUI ${GEOM_ROOT_DIR}/lib/salome)
FIND_LIBRARY(GEOM_GEOMShapeRec GEOMShapeRec ${GEOM_ROOT_DIR}/lib/salome)

View File

@ -126,10 +126,30 @@ SET(GEOM_STEPExport STEPExport)
SET(GEOM_STEPImport STEPImport)
SET(GEOM_STLExport STLExport)
SET(GEOM_ShHealOper ShHealOper)
SET(GEOM_VTKExport VTKExport)
SET(GEOM_XAO XAO)
SET(GEOM_AdvancedEngine AdvancedEngine)
SET(GEOM_AdvancedGUI AdvancedGUI)
SET(GEOM_BasicGUI BasicGUI)
SET(GEOM_BlocksGUI BlocksGUI)
SET(GEOM_BooleanGUI BooleanGUI)
SET(GEOM_BuildGUI BuildGUI)
SET(GEOM_DisplayGUI DisplayGUI)
SET(GEOM_DlgRef DlgRef)
SET(GEOM_GEOM GEOM)
SET(GEOM_EntityGUI EntityGUI)
SET(GEOM_GEOMBase GEOMBase)
SET(GEOM_GEOMFiltersSelection GEOMFiltersSelection)
SET(GEOM_GEOM GEOM)
SET(GEOM_GEOMToolsGUI GEOMToolsGUI)
SET(GEOM_GenerationGUI GenerationGUI)
SET(GEOM_GroupGUI GroupGUI)
SET(GEOM_Material Material)
SET(GEOM_MeasureGUI MeasureGUI)
SET(GEOM_GEOMObject GEOMObject)
SET(GEOM_OCC2VTK OCC2VTK)
SET(GEOM_VTKExport VTKExport)
SET(GEOM_OperationGUI OperationGUI)
SET(GEOM_PrimitiveGUI PrimitiveGUI)
SET(GEOM_RepairGUI RepairGUI)
SET(GEOM_TransformationGUI TransformationGUI)
SET(GEOM_ImportExportGUI ImportExportGUI)
SET(GEOM_GEOMShapeRec GEOMShapeRec)

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@ -1 +0,0 @@
<li>\subpage create_smoothingsurface_page</li>

View File

@ -0,0 +1,21 @@
/*!
\page export_xao_page Export XAO
To export a shape in the \b XAO format, in the <b>Main Menu</b> select <b>New Entity ->
Import / Export -> Export XAO </b>
Specify the parameters of the Export XAO dialog box and press "Apply" or "Apply & Close" button.
<b>TUI Command:</b> <em>geompy.MakeExportXAO(Shape, FileName, Groups, Fields)</em>
<b>Arguments:</b>
- \b Shape - The shape to export
- \b FileName - The name of the file to create
- \b Groups - The list of groups to export
- \b Fields - The list of fields to export
\image html exportxao_dlg.png
*/

View File

@ -0,0 +1,8 @@
/*!
\page import_xao_page Import XAO
To import a shape in the \b XAO format, in the <b>Main Menu</b> select <b>New Entity ->
Import / Export -> Import XAO </b>
*/

View File

@ -4,18 +4,18 @@
\image html geomscreen.png
\b Geometry module of SALOME is destined for:
\b Geometry module of SALOME is destined for:
- \subpage import_export_geom_obj_page "import and export of geometrical models"
in IGES, BREP and STEP formats;
- \subpage create_geom_obj_page "construction of geometrical objects"
using a wide range of functions;
using a wide range of functions;
- \subpage view_geom_obj_page "viewing geometrical objects" in the OCC
viewer;
viewer;
- \subpage transform_geom_obj_page "transformation of geometrical objects"
using various algorithms;
- \subpage repairing_operations_page "optimization of geometrical objects";
- viewing \subpage geometrical_obj_prop_page "geometrical object properties"
and other information about geometrical objects using
and other information about geometrical objects using
\subpage using_measurement_tools_page "measurement tools";
- \subpage pictures_page "designing shapes from pictures";
- easily setting parameters via the variables predefined in
@ -24,6 +24,8 @@
The possibility to classify the created geometrical objects by moving it into early created container (folder) is detailed on
\subpage arranging_study_objects_page section.
XAO format describing a shape with its topology, groups and fields is detailed on \subpage xao_format_page section.
Geometry module preferences are described in the
\subpage geometry_preferences_page section of SALOME Geometry Help.

View File

@ -0,0 +1,18 @@
\anchor tui_creation_exportxao
<br><h2>Creation of ExportXAO</h2>
\code
import geompy
import salome
gg = salome.ImportComponentGUI("GEOM")
# create ExportXAO object
exportxao = geompy.MakeExportXAO([value], [value], [value], [value])
# add object in the study
id_exportxao = geompy.addToStudy(exportxao,"ExportXAO")
# display exportxao
gg.createAndDisplayGO(id_exportxao)
\endcode

View File

@ -0,0 +1,10 @@
/*!
\page xao_format_page The XAO format
XAO is a file format which describes a shape with its topology, groups and fields.
- \subpage export_xao_page "Export"
- \subpage import_xao_page "Import"
*/

View File

@ -3703,6 +3703,31 @@ module GEOM
* \return list of all texture IDs avaiable for the current study
*/
ListOfLong GetAllTextures();
/*!
* Export a shape to XAO format
* \param shape The shape to export
* \param groups The list of groups to export
* \param fields The list of fields to export
* \param author The author of the export
* \param fileName The name of the file to export
* \return boolean indicating if export was successful.
*/
boolean ExportXAO(in GEOM_Object shape,
in ListOfGO groups, in ListOfGO fields,
in string author, in string fileName);
/*!
* Import a shape from XAO format
* \param fileName The name of the file to import
* \param shape The imported shape
* \param subShapes The list of imported subShapes
* \param groups The list of imported groups
* \param fields The list of imported fields
* \return boolean indicating if import was successful.
*/
boolean ImportXAO(in string fileName, out GEOM_Object shape,
out ListOfGO subShapes, out ListOfGO groups, out ListOfGO fields);
};
// # GEOM_IKindOfShape:

View File

@ -262,6 +262,11 @@ module GEOM
out string_array thePatterns) ;
void ExportTranslators (out string_array theFormats,
out string_array thePatterns) ;
boolean ExportXAO(in GEOM_Object shape,
in ListOfGO groups, in ListOfGO fields,
in string author, in string fileName);
boolean ImportXAO(in string fileName, out GEOM_Object shape,
out ListOfGO subShapes, out ListOfGO groups, out ListOfGO fields);
//-----------------------------------------------------------//
// TransformOperations //

View File

@ -261,6 +261,7 @@ SET( _res_files
dlg_pipetshapefilletrf.png
dividedcylinder.png dividedcylinder_r_h.png
smoothingsurface.png smoothingsurface_lpoints.png tree_smoothingsurface.png
exportxao.png importxao.png
##@@ insert new functions before this line @@ do not remove this line @@##
)
INSTALL(FILES ${_res_files} DESTINATION ${SALOME_GEOM_INSTALL_RES_DATA})

View File

@ -54,6 +54,7 @@
<objref name="GEOM_IAdvancedOperations" id="IDL:GEOM/GEOM_IAdvancedOperations:1.0" />
<sequence name="ListOfLong" content="int" />
<sequence name="ListOfGO" content="GEOM_Object" />
<sequence name="ListOfBool" content="boolean" />
<sequence name="string_array" content="string" />
<struct name="BCError" >
<member name="incriminated" type="ListOfLong"/>
@ -73,7 +74,7 @@
<component-comment>Geometry component</component-comment>
<component-multistudy>1</component-multistudy>
<component-icone>ModuleGeom.png</component-icone>
<component-impltype>1</component-impltype>
<component-impltype>1</component-impltype>
<!-- component interface list -->
<component-interface-list>
@ -594,44 +595,44 @@
</outParameter-list>
<DataStream-list></DataStream-list>
</component-service>
<component-service>
<service-name>GetDumpName</service-name>
<service-author></service-author>
<service-version></service-version>
<service-comment>unknown</service-comment>
<service-by-default>0</service-by-default>
<inParameter-list>
<inParameter>
<inParameter-name>theStudyEntry</inParameter-name>
<inParameter-type>string</inParameter-type>
<inParameter-comment>unknown</inParameter-comment>
</inParameter>
</inParameter-list>
<outParameter-list>
<outParameter>
<outParameter-name>return</outParameter-name>
<outParameter-type>string</outParameter-type>
<outParameter-comment>unknown</outParameter-comment>
</outParameter>
</outParameter-list>
<DataStream-list></DataStream-list>
</component-service>
<component-service>
<service-name>GetAllDumpNames</service-name>
<service-author></service-author>
<service-version></service-version>
<service-comment>unknown</service-comment>
<service-by-default>0</service-by-default>
<inParameter-list></inParameter-list>
<outParameter-list>
<outParameter>
<outParameter-name>return</outParameter-name>
<outParameter-type>string_array</outParameter-type>
<outParameter-comment>unknown</outParameter-comment>
</outParameter>
</outParameter-list>
<DataStream-list></DataStream-list>
</component-service>
<component-service>
<service-name>GetDumpName</service-name>
<service-author></service-author>
<service-version></service-version>
<service-comment>unknown</service-comment>
<service-by-default>0</service-by-default>
<inParameter-list>
<inParameter>
<inParameter-name>theStudyEntry</inParameter-name>
<inParameter-type>string</inParameter-type>
<inParameter-comment>unknown</inParameter-comment>
</inParameter>
</inParameter-list>
<outParameter-list>
<outParameter>
<outParameter-name>return</outParameter-name>
<outParameter-type>string</outParameter-type>
<outParameter-comment>unknown</outParameter-comment>
</outParameter>
</outParameter-list>
<DataStream-list></DataStream-list>
</component-service>
<component-service>
<service-name>GetAllDumpNames</service-name>
<service-author></service-author>
<service-version></service-version>
<service-comment>unknown</service-comment>
<service-by-default>0</service-by-default>
<inParameter-list></inParameter-list>
<outParameter-list>
<outParameter>
<outParameter-name>return</outParameter-name>
<outParameter-type>string_array</outParameter-type>
<outParameter-comment>unknown</outParameter-comment>
</outParameter>
</outParameter-list>
<DataStream-list></DataStream-list>
</component-service>
</component-service-list>
</component-interface-list>
<constraint>hostname = localhost</constraint>
@ -5301,6 +5302,43 @@
</outParameter-list>
<DataStream-list></DataStream-list>
</component-service>
<component-service>
<service-name>MakeExportXAO</service-name>
<service-author></service-author>
<service-version></service-version>
<service-comment>unknown</service-comment>
<service-by-default>0</service-by-default>
<inParameter-list>
<inParameter>
<inParameter-name>theFileName</inParameter-name>
<inParameter-type>string</inParameter-type>
<inParameter-comment>The name of the exported file</inParameter-comment>
</inParameter>
<inParameter>
<inParameter-name>theExportingShape</inParameter-name>
<inParameter-type>GEOM_Object</inParameter-type>
<inParameter-comment>Shape to export</inParameter-comment>
</inParameter>
<inParameter>
<inParameter-name>thelGroups</inParameter-name>
<inParameter-type>GEOM_List</inParameter-type>
<inParameter-comment>List of groups to export</inParameter-comment>
</inParameter>
<inParameter>
<inParameter-name>thelFields</inParameter-name>
<inParameter-type>GEOM_List</inParameter-type>
<inParameter-comment>List of fields to export</inParameter-comment>
</inParameter>
</inParameter-list>
<outParameter-list>
<outParameter>
<outParameter-name>return</outParameter-name>
<outParameter-type>bool</outParameter-type>
<outParameter-comment>Result object</outParameter-comment>
</outParameter>
</outParameter-list>
<DataStream-list></DataStream-list>
</component-service>
<!-- @@ insert new functions before this line @@ do not remove this line @@ -->
</component-service-list>
</component-interface-list>

BIN
resources/exportxao.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 608 B

BIN
resources/importxao.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 544 B

View File

@ -23,7 +23,8 @@
SET(SUBDIRS_COMMON
ARCHIMEDE BlockFix GEOMAlgo SKETCHER GEOM BREPExport
BREPImport IGESExport IGESImport STEPExport STEPImport STLExport
ShHealOper GEOMUtils GEOMImpl GEOM_I GEOMClient GEOM_I_Superv GEOM_SWIG GEOM_PY
ShHealOper GEOMUtils XAO XAO_Swig GEOMImpl GEOM_I GEOMClient GEOM_I_Superv GEOM_SWIG GEOM_PY
AdvancedEngine
)
##
@ -43,7 +44,7 @@ IF(SALOME_BUILD_GUI)
OBJECT OCC2VTK VTKExport DlgRef GEOMFiltersSelection Material GEOMGUI
GEOMBase GEOMToolsGUI DisplayGUI BasicGUI PrimitiveGUI GenerationGUI
EntityGUI BuildGUI BooleanGUI TransformationGUI OperationGUI
RepairGUI MeasureGUI GroupGUI BlocksGUI AdvancedGUI AdvancedEngine
RepairGUI MeasureGUI GroupGUI BlocksGUI AdvancedGUI ImportExportGUI
GEOM_SWIG_WITHIHM
)
ENDIF()

View File

@ -836,21 +836,24 @@ bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction, b
for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it, currObj++ ) {
GEOM::GEOM_Object_var obj=*it;
if ( publish ) {
QString aName = getNewObjectName(currObj);
if ( nbObjs > 1 ) {
if (aName.isEmpty())
aName = getPrefix(obj);
if (nbObjs <= 30) {
// Try to find a unique name
aName = GEOMBase::GetDefaultName(aName, extractPrefix());
} else {
// Don't check name uniqueness in case of numerous objects
aName = aName + "_" + QString::number(aNumber++);
}
} else {
// PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
if ( aName.isEmpty() )
aName = GEOMBase::GetDefaultName( getPrefix( obj ) );
QString aName = getObjectName(obj);
if (aName.isEmpty()) {
aName = getNewObjectName(currObj);
if ( nbObjs > 1 ) {
if (aName.isEmpty())
aName = getPrefix(obj);
if (nbObjs <= 30) {
// Try to find a unique name
aName = GEOMBase::GetDefaultName(aName, extractPrefix());
} else {
// Don't check name uniqueness in case of numerous objects
aName = aName + "_" + QString::number(aNumber++);
}
} else {
// PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
if ( aName.isEmpty() )
aName = GEOMBase::GetDefaultName( getPrefix( obj ) );
}
}
anEntryList << addInStudy( obj, aName.toLatin1().constData() );
// updateView=false
@ -978,13 +981,22 @@ GEOM::GEOM_Object_ptr GEOMBase_Helper::getFather( GEOM::GEOM_Object_ptr theObj )
return GEOM::GEOM_Object::_nil();
}
//================================================================
// Function : getObjectName
// Purpose : Redefine this method to return proper name for the given object
//================================================================
QString GEOMBase_Helper::getObjectName(GEOM::GEOM_Object_ptr object) const
{
return QString();
}
//================================================================
// Function : getNewObjectName
// Purpose : Redefine this method to return proper name for a new object
//================================================================
QString GEOMBase_Helper::getNewObjectName (int) const
{
return QString::null;
return QString();
}
//================================================================

View File

@ -164,6 +164,7 @@ protected:
// as a top-level object.
virtual QString getNewObjectName (int CurrObj = -1) const;
virtual QString getObjectName(GEOM::GEOM_Object_ptr object) const;
virtual bool extractPrefix() const;
virtual void addSubshapesToStudy();

View File

@ -1227,5 +1227,26 @@
<source>ICON_DLG_SCALE_ALONG_AXES</source>
<translation>scale_along_axes.png</translation>
</message>
<message>
<source>ICON_DLG_EXPORTXAO</source>
<translation>exportxao.png</translation>
</message>
<message>
<source>ICO_EXPORTXAO</source>
<translation>exportxao.png</translation>
</message>
<message>
<source>ICON_DLG_IMPORTXAO</source>
<translation>importxao.png</translation>
</message>
<message>
<source>ICO_IMPORTXAO</source>
<translation>importxao.png</translation>
</message>
<message>
<source>ICON_OBJBROWSER_IMPORTEXPORT_204</source>
<translation>tree_exportxao.png</translation>
</message>
<!-- @@ insert new functions before this line @@ do not remove this line @@ -->
</context>
</TS>

View File

@ -4881,6 +4881,50 @@ Ignoring units will cause model scaling (as dimensions are supposed to be specif
<source>GEOM_SELECT_IMAGE</source>
<translation>Select image...</translation>
</message>
<message>
<source>MEN_IMPORTEXPORT</source>
<translation>Import / Export</translation>
</message>
<message>
<source>TOP_EXPORTXAO</source>
<translation>Export to XAO</translation>
</message>
<message>
<source>MEN_EXPORTXAO</source>
<translation>Export XAO</translation>
</message>
<message>
<source>STB_EXPORTXAO</source>
<translation>Export shape to XAO format</translation>
</message>
<message>
<source>TOP_IMPORTXAO</source>
<translation>Import from XAO</translation>
</message>
<message>
<source>MEN_IMPORTXAO</source>
<translation>Import XAO</translation>
</message>
<message>
<source>STB_IMPORTXAO</source>
<translation>Import shape from XAO format</translation>
</message>
<message>
<source>GEOM_IMPORTEXPORT_204</source>
<translation>Export XAO</translation>
</message>
<message>
<source>GEOM_SELECT_EXPORT_XAO</source>
<translation>Export to XAO</translation>
</message>
<message>
<source>XAO_FILES</source>
<translation>XAO files (*.xao)</translation>
</message>
<message>
<source>TOOLS_IMPORTEXPORT</source>
<translation>Import / Export</translation>
</message>
</context>
<context>
<name>BasicGUI_CurveDlg</name>
@ -5768,4 +5812,62 @@ Do you want to create new material?</translation>
<translation>(No info available)</translation>
</message>
</context>
<context>
<name>ImportExportGUI_ExportXAODlg</name>
<message>
<source>GEOM_EXPORTXAO_TITLE</source>
<translation>Export XAO</translation>
</message>
<message>
<source>GEOM_EXPORTXAO</source>
<translation>Export XAO</translation>
</message>
<message>
<source>GEOM_EXPORTXAO_EXPORTINGSHAPE</source>
<translation>Shape</translation>
</message>
<message>
<source>GEOM_EXPORTXAO_FILENAME</source>
<translation>File Name</translation>
</message>
<message>
<source>GEOM_EXPORTXAO_AUTHOR</source>
<translation>Author</translation>
</message>
<message>
<source>GEOM_EXPORTXAO_LGROUPS</source>
<translation>Groups</translation>
</message>
<message>
<source>GEOM_EXPORTXAO_LFIELDS</source>
<translation>Fields</translation>
</message>
</context>
<context>
<name>ImportExportGUI_ImportXAODlg</name>
<message>
<source>GEOM_IMPORTXAO_TITLE</source>
<translation>Import XAO</translation>
</message>
<message>
<source>GEOM_IMPORTXAO</source>
<translation>Import XAO</translation>
</message>
<message>
<source>GEOM_IMPORTXAO_IMPORTINGSHAPE</source>
<translation>Shape</translation>
</message>
<message>
<source>GEOM_IMPORTXAO_FILENAME</source>
<translation>File Name</translation>
</message>
<message>
<source>GEOM_IMPORTXAO_LGROUPS</source>
<translation>Groups</translation>
</message>
<message>
<source>GEOM_IMPORTXAO_LFIELDS</source>
<translation>Fields</translation>
</message>
</context>
</TS>

View File

@ -4895,6 +4895,50 @@ le paramètre &apos;%1&apos; aux préférences du module Géométrie.</translati
<source>GEOM_SELECT_IMAGE</source>
<translation>Sélectionner une image...</translation>
</message>
<message>
<source>MEN_IMPORTEXPORT</source>
<translation>Import / Export</translation>
</message>
<message>
<source>TOP_EXPORTXAO</source>
<translation>Export XAO</translation>
</message>
<message>
<source>MEN_EXPORTXAO</source>
<translation>Export XAO</translation>
</message>
<message>
<source>STB_EXPORTXAO</source>
<translation>Exporter une forme au format XAO</translation>
</message>
<message>
<source>TOP_IMPORTXAO</source>
<translation>Import XAO</translation>
</message>
<message>
<source>MEN_IMPORTXAO</source>
<translation>Import XAO</translation>
</message>
<message>
<source>STB_IMPORTXAO</source>
<translation>Importer une forme au format XAO</translation>
</message>
<message>
<source>GEOM_IMPORTEXPORT_204</source>
<translation>Export XAO</translation>
</message>
<message>
<source>GEOM_SELECT_EXPORT_XAO</source>
<translation>Export XAO</translation>
</message>
<message>
<source>XAO_FILES</source>
<translation>Fichiers XAO (*.xao)</translation>
</message>
<message>
<source>TOOLS_IMPORTEXPORT</source>
<translation>Import / Export</translation>
</message>
</context>
<context>
<name>BasicGUI_CurveDlg</name>
@ -5782,6 +5826,64 @@ Voulez-vous en créer un nouveau ?</translation>
<translation type="unfinished">Information</translation>
</message>
</context>
<context>
<name>ImportExportGUI_ExportXAODlg</name>
<message>
<source>GEOM_EXPORTXAO_TITLE</source>
<translation>Export XAO</translation>
</message>
<message>
<source>GEOM_EXPORTXAO</source>
<translation>Export XAO</translation>
</message>
<message>
<source>GEOM_EXPORTXAO_EXPORTINGSHAPE</source>
<translation>Objet</translation>
</message>
<message>
<source>GEOM_EXPORTXAO_FILENAME</source>
<translation>Fichier</translation>
</message>
<message>
<source>GEOM_EXPORTXAO_AUTHOR</source>
<translation>Auteur</translation>
</message>
<message>
<source>GEOM_EXPORTXAO_LGROUPS</source>
<translation>Groupes</translation>
</message>
<message>
<source>GEOM_EXPORTXAO_LFIELDS</source>
<translation>Champs</translation>
</message>
</context>
<context>
<name>ImportExportGUI_ImportXAODlg</name>
<message>
<source>GEOM_IMPORTXAO_TITLE</source>
<translation>Import XAO</translation>
</message>
<message>
<source>GEOM_IMPORTXAO</source>
<translation>Import XAO</translation>
</message>
<message>
<source>GEOM_IMPORTXAO_IMPORTINGSHAPE</source>
<translation>Objet</translation>
</message>
<message>
<source>GEOM_IMPORTXAO_FILENAME</source>
<translation>Fichier</translation>
</message>
<message>
<source>GEOM_IMPORTXAO_LGROUPS</source>
<translation>Groupes</translation>
</message>
<message>
<source>GEOM_IMPORTXAO_LFIELDS</source>
<translation>Champs</translation>
</message>
</context>
</TS>

View File

@ -641,6 +641,10 @@ void GeometryGUI::OnGUIEvent( int id, const QVariant& theParam )
case GEOMOp::OpExplodeBlock: // MENU BLOCKS - EXPLODE ON BLOCKS
libName = "BlocksGUI";
break;
case GEOMOp::OpExportXAO: // MENU NEW ENTITY - IMPORTEXPORT - EXPORTXAO
case GEOMOp::OpImportXAO: // MENU NEW ENTITY - IMPORTEXPORT - IMPORTXAO
libName = "ImportExportGUI";
break;
//case GEOMOp::OpAdvancedNoOp: // NO OPERATION (advanced operations base)
//case GEOMOp::OpPipeTShape: // MENU NEW ENTITY - ADVANCED - PIPE TSHAPE
//case GEOMOp::OpPipeTShapeGroups: // MENU NEW ENTITY - ADVANCED - PIPE TSHAPE GROUPS
@ -1052,6 +1056,10 @@ void GeometryGUI::initialize( CAM_Application* app )
createGeomAction( GEOMOp::OpDecrNbIsos, "", "", 0, false,
"Geometry:Decrease number of isolines");
// Import/Export XAO
createGeomAction( GEOMOp::OpExportXAO, "EXPORTXAO" );
createGeomAction( GEOMOp::OpImportXAO, "IMPORTXAO" );
//createGeomAction( GEOMOp::OpPipeTShape, "PIPETSHAPE" );
//createGeomAction( GEOMOp::OpDividedDisk, "DIVIDEDDISK" );
//createGeomAction( GEOMOp::OpDividedCylinder, "DIVIDEDCYLINDER" );
@ -1105,6 +1113,10 @@ void GeometryGUI::initialize( CAM_Application* app )
createMenu( GEOMOp::OpPipePath, genId, -1 );
#endif
int impexpId = createMenu( tr( "MEN_IMPORTEXPORT" ), newEntId, -1 );
createMenu( GEOMOp::OpExportXAO, impexpId, -1 );
createMenu( GEOMOp::OpImportXAO, impexpId, -1 );
//int advId = createMenu( tr( "MEN_ADVANCED" ), newEntId, -1 );
//createMenu( GEOMOp::OpSmoothingSurface, advId, -1 );
//@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@ do not remove this line @@ do not remove this line @@//
@ -1380,6 +1392,10 @@ void GeometryGUI::initialize( CAM_Application* app )
createTool( GEOMOp::OpFeatureDetect, picturesTbId );
#endif
int impexpTbId = createTool( tr( "TOOL_IMPORTEXPORT" ) );
createTool( GEOMOp::OpExportXAO, impexpTbId );
createTool( GEOMOp::OpImportXAO, impexpTbId );
//int advancedTbId = createTool( tr( "TOOL_ADVANCED" ) );
//createTool( GEOMOp::OpSmoothingSurface, advancedTbId );
//@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@ do not remove this line @@ do not remove this line @@//

View File

@ -193,6 +193,9 @@ namespace GEOMOp {
OpQuadFace = 6102, // MENU BLOCKS - QUADRANGLE FACE
OpPropagate = 6103, // MENU BLOCKS - PROPAGATE
OpExplodeBlock = 6104, // MENU BLOCKS - EXPLODE ON BLOCKS
// ImportExport ----------------//--------------------------------
OpExportXAO = 6200, // MENU NEW ENTITY - IMPORTEXPORT - EXPORTXAO
OpImportXAO = 6201, // MENU NEW ENTITY - IMPORTEXPORT - IMPORTXAO
// AdvancedGUI -----------------//--------------------------------
OpAdvancedNoOp = 10000, // NO OPERATION (advanced operations base)
//OpPipeTShape = 10001, // MENU NEW ENTITY - ADVANCED - PIPE TSHAPE

View File

@ -25,19 +25,22 @@ INCLUDE_DIRECTORIES(
${PTHREAD_INCLUDE_DIR}
${KERNEL_INCLUDE_DIRS}
${PYTHON_INCLUDE_DIRS}
${LIBXML2_INCLUDE_DIR}
${PROJECT_SOURCE_DIR}/src/ShHealOper
${PROJECT_SOURCE_DIR}/src/GEOM
${PROJECT_SOURCE_DIR}/src/BlockFix
${PROJECT_SOURCE_DIR}/src/GEOMAlgo
${PROJECT_SOURCE_DIR}/src/GEOMUtils
${PROJECT_SOURCE_DIR}/src/SKETCHER
${PROJECT_SOURCE_DIR}/src/ARCHIMEDE
${PROJECT_SOURCE_DIR}/src/GEOM
${PROJECT_SOURCE_DIR}/src/BlockFix
${PROJECT_SOURCE_DIR}/src/GEOMAlgo
${PROJECT_SOURCE_DIR}/src/GEOMUtils
${PROJECT_SOURCE_DIR}/src/SKETCHER
${PROJECT_SOURCE_DIR}/src/ARCHIMEDE
${PROJECT_SOURCE_DIR}/src/XAO
${CMAKE_CURRENT_SOURCE_DIR}
)
# additional preprocessor / compiler flags
ADD_DEFINITIONS(
${CAS_DEFINITIONS}
${LIBXML2_DEFINITIONS}
${PYTHON_DEFINITIONS}
)
@ -46,7 +49,8 @@ SET(_link_LIBRARIES
${CAS_TKFeat}
${CAS_TKFillet}
${PYTHON_LIBRARIES}
ShHealOper GEOMbasic BlockFix GEOMAlgo GEOMUtils GEOMSketcher GEOMArchimede
${LIBXML2_LIBRARIES}
ShHealOper GEOMbasic BlockFix GEOMAlgo GEOMUtils GEOMSketcher GEOMArchimede XAO
${KERNEL_SALOMELocalTrace}
)
@ -168,6 +172,8 @@ SET(GEOMImpl_HEADERS
GEOMImpl_GlueDriver.hxx
GEOMImpl_Types.hxx
GEOM_GEOMImpl.hxx
GEOMImpl_IImportExportXAO.hxx
GEOMImpl_XAODriver.hxx
)
# --- sources ---
@ -236,6 +242,7 @@ SET(GEOMImpl_SOURCES
GEOMImpl_FillingDriver.cxx
GEOMImpl_GlueDriver.cxx
GEOMImpl_FieldDriver.cxx
GEOMImpl_XAODriver.cxx
)
# --- rules ---

View File

@ -83,6 +83,7 @@
#include <GEOMImpl_GlueDriver.hxx>
#include <GEOMImpl_MeasureDriver.hxx>
#include <GEOMImpl_FieldDriver.hxx>
#include <GEOMImpl_XAODriver.hxx>
//=============================================================================
/*!
@ -167,6 +168,11 @@ GEOMImpl_Gen::GEOMImpl_Gen()
// Field
TFunction_DriverTable::Get()->AddDriver(GEOMImpl_FieldDriver::GetID(), new GEOMImpl_FieldDriver());
// XAO operations
TFunction_DriverTable::Get()->AddDriver(GEOMImpl_XAODriver::GetID(), new GEOMImpl_XAODriver());
/*@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@*/
SetEngine(this);
}

View File

@ -0,0 +1,41 @@
// 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
// 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
#ifndef _GEOMImpl_IImportExportXAO_HXX_
#define _GEOMImpl_IImportExportXAO_HXX_
#include "GEOM_Function.hxx"
#define IMPORTEXPORTXAO_ARG_DATA 1
class GEOMImpl_IImportExportXAO
{
public:
GEOMImpl_IImportExportXAO(Handle(GEOM_Function) theFunction): _func(theFunction) {}
void SetData(const TCollection_AsciiString& data) { _func->SetString(IMPORTEXPORTXAO_ARG_DATA, data); }
const TCollection_AsciiString GetData() { return _func->GetString(IMPORTEXPORTXAO_ARG_DATA); }
private:
Handle(GEOM_Function) _func;
};
#endif // _GEOMImpl_IExportXAO_HXX_

View File

@ -30,9 +30,21 @@
#include <GEOMImpl_ICopy.hxx>
#include <GEOMImpl_IImportExport.hxx>
#include <GEOMImpl_Types.hxx>
#include "GEOMImpl_IShapesOperations.hxx"
#include "GEOMImpl_IGroupOperations.hxx"
#include "GEOMImpl_XAODriver.hxx"
#include "GEOMImpl_IImportExportXAO.hxx"
#include <GEOM_Function.hxx>
#include <GEOM_PythonDump.hxx>
#include "GEOM_ISubShape.hxx"
#include <XAO_Xao.hxx>
#include <XAO_Geometry.hxx>
#include <XAO_BrepGeometry.hxx>
#include <XAO_Group.hxx>
#include <XAO_Field.hxx>
#include <XAO_XaoUtils.hxx>
#include <Basics_OCCTVersion.hxx>
@ -44,6 +56,7 @@
#include <TFunction_Driver.hxx>
#include <TFunction_Logbook.hxx>
#include <TDF_Tool.hxx>
#include <TDataStd_Integer.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Vertex.hxx>
@ -70,6 +83,8 @@ GEOMImpl_IInsertOperations::GEOMImpl_IInsertOperations(GEOM_Engine* theEngine, i
: GEOM_IOperations(theEngine, theDocID)
{
MESSAGE("GEOMImpl_IInsertOperations::GEOMImpl_IInsertOperations");
myShapesOperations = new GEOMImpl_IShapesOperations(GetEngine(), GetDocID());
myGroupOperations = new GEOMImpl_IGroupOperations(GetEngine(), GetDocID());
}
//=============================================================================
@ -80,6 +95,8 @@ GEOMImpl_IInsertOperations::GEOMImpl_IInsertOperations(GEOM_Engine* theEngine, i
GEOMImpl_IInsertOperations::~GEOMImpl_IInsertOperations()
{
MESSAGE("GEOMImpl_IInsertOperations::~GEOMImpl_IInsertOperations");
delete myShapesOperations;
delete myGroupOperations;
}
//=============================================================================
@ -755,3 +772,404 @@ std::list<int> GEOMImpl_IInsertOperations::GetAllTextures()
SetErrorCode(OK);
return id_list;
}
TopAbs_ShapeEnum getGroupDimension(XAO::Group* group)
{
XAO::Dimension dim = group->getDimension();
TopAbs_ShapeEnum rdim;
switch ( dim )
{
case XAO::VERTEX:
rdim = TopAbs_VERTEX; break;
case XAO::EDGE:
rdim = TopAbs_EDGE; break;
case XAO::FACE:
rdim = TopAbs_FACE; break;
case XAO::SOLID:
rdim = TopAbs_SOLID; break;
default:
rdim = TopAbs_COMPOUND; break;
}
return rdim;
}
XAO::Dimension shapeEnumToDimension(const TopAbs_ShapeEnum& shape)
{
XAO::Dimension dim;
switch( shape ) {
case TopAbs_VERTEX:
dim = XAO::VERTEX; break;
case TopAbs_EDGE:
dim = XAO::EDGE; break;
case TopAbs_FACE:
dim = XAO::FACE; break;
case TopAbs_SOLID:
dim = XAO::SOLID; break;
default:
throw SALOME_Exception("Bad type"); // TODO
}
return dim;
}
void GEOMImpl_IInsertOperations::exportGroups(std::list<Handle(GEOM_Object)> groupList, XAO::Xao* xaoObject, XAO::BrepGeometry* geometry)
{
// add the groups
std::list<Handle(GEOM_Object)>::iterator groupIterator = groupList.begin();
while (groupIterator != groupList.end())
{
Handle(GEOM_Object) currGroup = (*groupIterator++);
Handle(TColStd_HArray1OfInteger) groupIds = myGroupOperations->GetObjects(currGroup);
TopAbs_ShapeEnum shapeGroup = myGroupOperations->GetType(currGroup);
XAO::Dimension dim = shapeEnumToDimension(shapeGroup);
XAO::Group* group = xaoObject->addGroup(dim, currGroup->GetName().ToCString());
switch (shapeGroup)
{
case TopAbs_VERTEX:
for (int i = 1; i <= groupIds->Length(); i++)
{
std::string ref = XAO::XaoUtils::intToString(groupIds->Value(i));
int index = geometry->getVertexIndexByReference(ref);
group->add(index);
}
break;
case TopAbs_EDGE:
for (int i = 1; i <= groupIds->Length(); i++)
{
std::string ref = XAO::XaoUtils::intToString(groupIds->Value(i));
int index = geometry->getEdgeIndexByReference(ref);
group->add(index);
}
break;
case TopAbs_FACE:
for (int i = 1; i <= groupIds->Length(); i++)
{
std::string ref = XAO::XaoUtils::intToString(groupIds->Value(i));
int index = geometry->getFaceIndexByReference(ref);
group->add(index);
}
break;
case TopAbs_SOLID:
for (int i = 1; i <= groupIds->Length(); i++)
{
std::string ref = XAO::XaoUtils::intToString(groupIds->Value(i));
int index = geometry->getSolidIndexByReference(ref);
group->add(index);
}
break;
}
}
}
void GEOMImpl_IInsertOperations::exportFields(std::list<Handle(GEOM_Object)> fieldList, XAO::Xao* xaoObject, XAO::BrepGeometry* geometry)
{
// TODO
}
void GEOMImpl_IInsertOperations::exportSubshapes(const Handle(GEOM_Object)& shape, XAO::BrepGeometry* geometry)
{
Handle(TColStd_HSequenceOfTransient) subObjects = myShapesOperations->GetExistingSubObjects(shape, false);
int nbSubObjects = subObjects->Length();
// set the names of the sub shapes
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)
{
int subIndex = myShapesOperations->GetSubShapeIndex(shape, subObject);
switch (subObject->GetValue().ShapeType())
{
case TopAbs_VERTEX:
geometry->changeVertexName(subIndex, subObject->GetName().ToCString());
break;
case TopAbs_EDGE:
geometry->changeEdgeName(subIndex, subObject->GetName().ToCString());
break;
case TopAbs_FACE:
geometry->changeFaceName(subIndex, subObject->GetName().ToCString());
break;
case TopAbs_SOLID:
geometry->changeSolidName(subIndex, subObject->GetName().ToCString());
break;
}
}
}
}
//=============================================================================
/*!
* Export a shape to XAO format
* \param shape The shape to export
* \param groups The list of groups to export
* \param fields The list of fields to export
* \param fileName The name of the file to exported
* \return boolean indicating if export was succeful.
*/
//=============================================================================
bool GEOMImpl_IInsertOperations::ExportXAO(Handle(GEOM_Object) shape,
std::list<Handle(GEOM_Object)> groupList,
std::list<Handle(GEOM_Object)> fieldList,
const char* author,
const char* fileName)
{
SetErrorCode(KO);
if (shape.IsNull()) return 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_XAODriver::GetID(), IMPORTEXPORT_EXPORTXAO);
if (exportFunction.IsNull()) return false;
if (exportFunction->GetDriverGUID() != GEOMImpl_XAODriver::GetID()) return false;
// create the XAO object
XAO::Xao* xaoObject = new XAO::Xao();
xaoObject->setAuthor(author);
// add the geometry
XAO::BrepGeometry* geometry = (XAO::BrepGeometry*)XAO::Geometry::createGeometry(XAO::BREP);
TopoDS_Shape topoShape = shape->GetValue();
exportFunction->SetValue(topoShape);
XAO::BrepGeometry* brep = (XAO::BrepGeometry*)geometry;
brep->setTopoDS_Shape(topoShape);
geometry->setName(shape->GetName().ToCString());
exportSubshapes(shape, geometry);
xaoObject->setGeometry(geometry);
exportGroups(groupList, xaoObject, geometry);
exportFields(fieldList, xaoObject, geometry);
// export the XAO to the file
xaoObject->exportXAO(fileName);
// make a Python command
GEOM::TPythonDump pd(exportFunction);
pd << "exported = geompy.ExportXAO(" << shape;
// list of groups
pd << ", [";
if (groupList.size() > 0)
{
std::list<Handle(GEOM_Object)>::iterator itGroup = groupList.begin();
pd << (*itGroup++);
while (itGroup != groupList.end())
{
pd << ", " << (*itGroup++);
}
}
// list of fields
pd << "], [";
if (fieldList.size() > 0)
{
std::list<Handle(GEOM_Object)>::iterator itField = fieldList.begin();
pd << (*itField++);
while (itField != fieldList.end())
{
pd << ", " << (*itField++);
}
}
pd << "], ";
pd << author << ", \"" << fileName << "\")";
SetErrorCode(OK);
delete xaoObject;
return true;
}
void GEOMImpl_IInsertOperations::importSubShapes(XAO::Geometry* xaoGeometry,
Handle(GEOM_Function) function, int shapeType, int dim,
Handle(TColStd_HSequenceOfTransient)& subShapeList)
{
Handle(GEOM_Object) subShape;
Handle(GEOM_Function) aFunction;
Handle(TColStd_HArray1OfInteger) anArray;
XAO::GeometricElementList::iterator elementIterator = xaoGeometry->begin((XAO::Dimension)dim);
for (; elementIterator != xaoGeometry->end((XAO::Dimension)dim); elementIterator++)
{
XAO::GeometricElement element = elementIterator->second;
if (!element.hasName())
continue;
std::string name = element.getName();
std::string ref = element.getReference();
int iref = XAO::XaoUtils::stringToInt(ref);
anArray = new TColStd_HArray1OfInteger(1, 1);
anArray->SetValue(1, iref);
subShape = GetEngine()->AddObject(GetDocID(), GEOM_SUBSHAPE);
Handle(GEOM_Function) aFunction = subShape->AddFunction(GEOM_Object::GetSubShapeID(), 1);
if (aFunction.IsNull())
return;
subShape->SetName(name.c_str());
subShape->SetType(shapeType);
GEOM_ISubShape aSSI(aFunction);
aSSI.SetMainShape(function);
aSSI.SetIndices(anArray);
//aFunction->SetValue(aValue);
subShapeList->Append(subShape);
// Put this subshape in the list of sub-shapes of theMainShape
function->AddSubShapeReference(aFunction);
}
}
//=============================================================================
/*!
* Import a shape from XAO format
* \param fileName The name of the file to import
* \param shape The imported shape
* \param subShapes The list of imported groups
* \param groups The list of imported groups
* \param fields The list of imported fields
* \return boolean indicating if import was succeful.
*/
//=============================================================================
bool GEOMImpl_IInsertOperations::ImportXAO(const char* fileName,
Handle(GEOM_Object)& shape,
Handle(TColStd_HSequenceOfTransient)& subShapes,
Handle(TColStd_HSequenceOfTransient)& groups,
Handle(TColStd_HSequenceOfTransient)& fields)
{
SetErrorCode(KO);
if (fileName == NULL || groups.IsNull() || fields.IsNull())
return false;
// Read the XAO
XAO::Xao* xaoObject = new XAO::Xao();
try
{
xaoObject->importXAO(fileName);
}
catch (XAO::XAO_Exception& exc)
{
delete xaoObject;
SetErrorCode(exc.what());
return false;
}
XAO::Geometry* xaoGeometry = xaoObject->getGeometry();
if (xaoGeometry == NULL)
{
delete xaoObject;
SetErrorCode("Cannot import XAO: geometry format not supported.");
return false;
}
// create the shape
shape = GetEngine()->AddObject(GetDocID(), GEOM_IMPORT);
Handle(GEOM_Function) function = shape->AddFunction(GEOMImpl_XAODriver::GetID(), IMPORTEXPORT_EXPORTXAO);
if (function.IsNull()) return false;
if (function->GetDriverGUID() != GEOMImpl_XAODriver::GetID()) return false;
// set the geometry
if (xaoGeometry->getFormat() == XAO::BREP)
{
XAO::BrepGeometry* brep = (XAO::BrepGeometry*)xaoGeometry;
TopoDS_Shape geomShape = brep->getTopoDS_Shape();
function->SetValue(geomShape);
shape->SetName(xaoGeometry->getName().c_str());
}
else
{
delete xaoObject;
SetErrorCode("Cannot import XAO: geometry format not supported.");
return false;
}
// create sub shapes with names
importSubShapes(xaoGeometry, function, GEOM_POINT, XAO::VERTEX, subShapes);
importSubShapes(xaoGeometry, function, GEOM_EDGE, XAO::EDGE, subShapes);
importSubShapes(xaoGeometry, function, GEOM_FACE, XAO::FACE, subShapes);
importSubShapes(xaoGeometry, function, GEOM_SOLID, XAO::SOLID, subShapes);
// create groups
int nbGroups = xaoObject->countGroups();
for (int i = 0; i < nbGroups; ++i)
{
XAO::Group* xaoGroup = xaoObject->getGroup(i);
// build an array with the indexes of the sub shapes
int nbElt = xaoGroup->count();
Handle(TColStd_HArray1OfInteger) array = new TColStd_HArray1OfInteger(1, nbElt);
int j = 0;
for (std::set<int>::iterator it = xaoGroup->begin(); it != xaoGroup->end(); ++it)
{
int index = (*it);
std::string ref = xaoGeometry->getElementReference(xaoGroup->getDimension(), index);
array->SetValue(++j, XAO::XaoUtils::stringToInt(ref));
}
// create the group with the array of sub shapes indexes
Handle(GEOM_Object) group = GetEngine()->AddSubShape(shape, array);
group->SetType(GEOM_GROUP);
group->SetName(xaoGroup->getName().c_str());
// Set a sub-shape type
TDF_Label freeLabel = group->GetFreeLabel();
TDataStd_Integer::Set(freeLabel, (Standard_Integer) getGroupDimension(xaoGroup));
groups->Append(group);
function = group->GetLastFunction();
}
// TODO: create the fields
// make a Python command
GEOM::TPythonDump pd(function);
pd << "(imported, " << shape << ", ";
// list of sub shapes
pd << "[";
int nbSubshapes = subShapes->Length();
std::cout << "Nb SubShapes = " << nbSubshapes << std::endl;
if (nbSubshapes > 0)
{
for (int i = 1; i <= nbSubshapes; i++)
{
Handle(GEOM_Object) obj = Handle(GEOM_Object)::DownCast(subShapes->Value(i));
pd << obj << ((i < nbSubshapes) ? ", " : "");
}
}
pd << "], [";
// list of groups
if (nbGroups > 0)
{
for (int i = 1; i <= nbGroups; i++)
{
Handle(GEOM_Object) obj = Handle(GEOM_Object)::DownCast(groups->Value(i));
pd << obj << ((i < nbGroups) ? ", " : "");
}
}
pd << "], [";
// list of fields
pd << "]";
pd << ") = geompy.ImportXAO(\"" << fileName << "\")";
delete xaoObject;
SetErrorCode(OK);
return true;
}

View File

@ -38,12 +38,21 @@
#include <list>
class GEOMImpl_IShapesOperations;
class GEOMImpl_IGroupOperations;
#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
class Handle_TColStd_HArray1OfByte;
#else
class Handle_TDataStd_HArray1OfByte;
#endif
namespace XAO {
class Geometry;
class BrepGeometry;
class Xao;
}
class GEOMImpl_IInsertOperations : public GEOM_IOperations {
public:
Standard_EXPORT GEOMImpl_IInsertOperations(GEOM_Engine* theEngine, int theDocID);
@ -51,10 +60,10 @@ class GEOMImpl_IInsertOperations : public GEOM_IOperations {
Standard_EXPORT Handle(GEOM_Object) MakeCopy (Handle(GEOM_Object) theOriginal);
Standard_EXPORT Handle(GEOM_Object) Import (const TCollection_AsciiString& theFileName,
const TCollection_AsciiString& theFormatType);
Standard_EXPORT TCollection_AsciiString ReadValue (const TCollection_AsciiString& theFileName,
const TCollection_AsciiString& theFormatType,
const TCollection_AsciiString& theParameterName);
@ -62,21 +71,21 @@ class GEOMImpl_IInsertOperations : public GEOM_IOperations {
Standard_EXPORT void Export (const Handle(GEOM_Object) theOriginal,
const TCollection_AsciiString& theFileName,
const TCollection_AsciiString& theFormatType);
Standard_EXPORT Standard_Boolean ImportTranslators (Handle(TColStd_HSequenceOfAsciiString)& theFormats,
Handle(TColStd_HSequenceOfAsciiString)& thePatterns);
Standard_EXPORT Standard_Boolean ExportTranslators (Handle(TColStd_HSequenceOfAsciiString)& theFormats,
Handle(TColStd_HSequenceOfAsciiString)& thePatterns);
Standard_EXPORT Standard_Boolean IsSupported (const Standard_Boolean isImport,
const TCollection_AsciiString& theFormat,
Handle(TCollection_HAsciiString)& theLibName);
Standard_EXPORT Handle(GEOM_Object) RestoreShape (std::istringstream& theStream);
Standard_EXPORT int LoadTexture(const TCollection_AsciiString& theTextureFile);
Standard_EXPORT int AddTexture(int theWidth, int theHeight,
#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
const Handle(TColStd_HArray1OfByte)& theTexture);
@ -89,16 +98,39 @@ class GEOMImpl_IInsertOperations : public GEOM_IOperations {
#else
Standard_EXPORT Handle(TDataStd_HArray1OfByte) GetTexture(int theTextureId,
#endif
int& theWidth, int& theHeight);
int& theWidth, int& theHeight);
Standard_EXPORT std::list<int> GetAllTextures();
Standard_EXPORT bool ExportXAO(Handle(GEOM_Object) shape,
std::list<Handle(GEOM_Object)> groupList,
std::list<Handle(GEOM_Object)> fieldList,
const char* author,
const char* fileName);
Standard_EXPORT bool ImportXAO(const char* fileName,
Handle(GEOM_Object)& shape,
Handle(TColStd_HSequenceOfTransient)& subShapes,
Handle(TColStd_HSequenceOfTransient)& groups,
Handle(TColStd_HSequenceOfTransient)& fields);
private:
Standard_Boolean InitResMgr ();
void importSubShapes(XAO::Geometry* xaoGeometry, Handle(GEOM_Function) function,
int shapeType, int dim,
Handle(TColStd_HSequenceOfTransient)& subshapeList);
void exportSubshapes(const Handle(GEOM_Object)& shape, XAO::BrepGeometry* geometry);
void exportFields(std::list<Handle(GEOM_Object)> fieldList, XAO::Xao* xaoObject,
XAO::BrepGeometry* geometry);
void exportGroups(std::list<Handle(GEOM_Object)> groupList, XAO::Xao* xaoObject,
XAO::BrepGeometry* geometry);
private:
Handle(Resource_Manager) myResMgr;
Handle(Resource_Manager) myResMgrUser;
GEOMImpl_IShapesOperations* myShapesOperations;
GEOMImpl_IGroupOperations* myGroupOperations;
};
#endif

View File

@ -109,6 +109,8 @@
#define GEOM_FIELD 52 // == GEOM_FIELD_OBJTYPE constant
#define GEOM_FIELD_STEP 53 // == GEOM_FIELD_STEP_OBJTYPE constant
#define GEOM_EXPORTXAO 54
//GEOM_Function types
#define COPY_WITH_REF 1
@ -355,5 +357,9 @@
#define MARKER_SHAPE 2
#define MARKER_PNT2VEC 3
// import/export XAO
#define IMPORTEXPORT_EXPORTXAO 1
#define IMPORTEXPORT_IMPORTXAO 2
// Advanced functions (base = 200)
#define ADVANCED_BASE 200 // NO OPERATION (advanced operations base)

View File

@ -0,0 +1,128 @@
// 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
// 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
#include <Standard_Stream.hxx>
#include <GEOMImpl_XAODriver.hxx>
#include <GEOMImpl_IImportExportXAO.hxx>
#include <GEOMImpl_Types.hxx>
#include <GEOM_Function.hxx>
#include <TFunction_Logbook.hxx>
#include <StdFail_NotDone.hxx>
#include "XAO_Xao.hxx"
#include "XAO_Geometry.hxx"
#include "XAO_Group.hxx"
#include "XAO_XaoUtils.hxx"
//@@ include required header files here @@//
//=======================================================================
//function : GetID
//purpose :
//=======================================================================
const Standard_GUID& GEOMImpl_XAODriver::GetID()
{
static Standard_GUID aGUID("FF1BBB71-5D14-4df2-980B-3A668264EA16");
return aGUID;
}
//=======================================================================
//function : GEOMImpl_XAODriver
//purpose :
//=======================================================================
GEOMImpl_XAODriver::GEOMImpl_XAODriver()
{
}
//=======================================================================
//function : Execute
//purpose :
//=======================================================================
Standard_Integer GEOMImpl_XAODriver::Execute(TFunction_Logbook& log) const
{
if (Label().IsNull()) return 0;
Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
GEOMImpl_IImportExportXAO iexao(function);
TCollection_AsciiString xao = iexao.GetData();
TopoDS_Shape shape;
Standard_Integer functionType = function->GetType();
if (functionType == IMPORTEXPORT_EXPORTXAO)
{
}
else if (functionType == IMPORTEXPORT_IMPORTXAO)
{
}
else
{
// other construction modes here
}
if (shape.IsNull()) return 0;
function->SetValue(shape);
log.SetTouched(Label());
return 1;
}
//=======================================================================
//function : GEOMImpl_XAODriver_Type_
//purpose :
//=======================================================================
Standard_EXPORT Handle_Standard_Type& GEOMImpl_XAODriver_Type_()
{
static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
if (aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
if (aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
if (aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
static Handle_Standard_Transient _Ancestors[] = { aType1, aType2, aType3, NULL };
static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_XAODriver",
sizeof(GEOMImpl_XAODriver),
1,
(Standard_Address) _Ancestors,
(Standard_Address) NULL);
return _aType;
}
//=======================================================================
//function : DownCast
//purpose :
//=======================================================================
const Handle(GEOMImpl_XAODriver) Handle(GEOMImpl_XAODriver)::DownCast(
const Handle(Standard_Transient)& AnObject)
{
Handle(GEOMImpl_XAODriver) _anOtherObject;
if (!AnObject.IsNull())
{
if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_XAODriver)))
{
_anOtherObject = Handle(GEOMImpl_XAODriver)((Handle(GEOMImpl_XAODriver)&) AnObject);
}
}
return _anOtherObject;
}

View File

@ -0,0 +1,147 @@
// 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
// 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
#ifndef _GEOMImpl_XAODriver_HXX
#define _GEOMImpl_XAODriver_HXX
#include <TFunction_Driver.hxx>
class Handle_Standard_Type;
class GEOMImpl_XAODriver;
Standard_EXPORT Handle_Standard_Type& STANDARD_TYPE(GEOMImpl_XAODriver);
class Handle(GEOMImpl_XAODriver): public Handle(TFunction_Driver)
{
public:
inline void* operator new(size_t, void* anAddress)
{
return anAddress;
}
inline void* operator new(size_t size)
{
return Standard::Allocate(size);
}
inline void operator delete(void *anAddress)
{
if (anAddress) Standard::Free((Standard_Address&) anAddress);
}
Handle(GEOMImpl_XAODriver) () :
Handle(TFunction_Driver)()
{
}
Handle(GEOMImpl_XAODriver) (const Handle(GEOMImpl_XAODriver)& aHandle) :
Handle(TFunction_Driver)(aHandle)
{
}
Handle(GEOMImpl_XAODriver) (const GEOMImpl_XAODriver* anItem) :
Handle(TFunction_Driver)((TFunction_Driver *) anItem)
{
}
Handle(GEOMImpl_XAODriver)& operator=(const Handle(GEOMImpl_XAODriver)& aHandle)
{
Assign(aHandle.Access());
return *this;
}
Handle(GEOMImpl_XAODriver)& operator=(const GEOMImpl_XAODriver* anItem)
{
Assign((Standard_Transient *) anItem);
return *this;
}
GEOMImpl_XAODriver* operator->()
{
return (GEOMImpl_XAODriver *) ControlAccess();
}
GEOMImpl_XAODriver* operator->() const
{
return (GEOMImpl_XAODriver *) ControlAccess();
}
Standard_EXPORT
~Handle(GEOMImpl_XAODriver)()
{
}
Standard_EXPORT
static const Handle(GEOMImpl_XAODriver) DownCast(const Handle(Standard_Transient)& AnObject);
};
class GEOMImpl_XAODriver: public TFunction_Driver
{
public:
inline void* operator new(size_t, void* anAddress)
{
return anAddress;
}
inline void* operator new(size_t size)
{
return Standard::Allocate(size);
}
inline void operator delete(void *anAddress)
{
if (anAddress) Standard::Free((Standard_Address&) anAddress);
}
// Methods PUBLIC
//
Standard_EXPORT
GEOMImpl_XAODriver();
Standard_EXPORT
virtual Standard_Integer Execute(TFunction_Logbook& log) const;
Standard_EXPORT
virtual void Validate(TFunction_Logbook&) const
{
}
Standard_EXPORT
Standard_Boolean MustExecute(const TFunction_Logbook&) const
{
return Standard_True;
}
Standard_EXPORT
static const Standard_GUID& GetID();
Standard_EXPORT
~GEOMImpl_XAODriver()
{
}
// Type management
//
Standard_EXPORT
friend Handle_Standard_Type& GEOMImpl_ExportXAODriver_Type_();
Standard_EXPORT
const Handle(Standard_Type)& DynamicType() const
{
return STANDARD_TYPE(GEOMImpl_XAODriver);
}
Standard_EXPORT
Standard_Boolean IsKind(const Handle(Standard_Type)& AType) const
{
return (STANDARD_TYPE(GEOMImpl_XAODriver) == AType || TFunction_Driver::IsKind(AType));
}
};
#endif // _GEOMImpl_XAODriver_HXX

View File

@ -71,5 +71,8 @@ FF1BBB69-5D14-4df2-980B-3A668264EA16 // Modify the Location
FF1BBB70-5D14-4df2-980B-3A668264EA16 // Projection
FF1BBB71-5D14-4df2-980B-3A668264EA16 // Export XAO
1C3A0F3F-729D-4E83-8232-78E74FC5637C // Pipe T-Shape
1C3A0F30-729D-4E83-8232-78E74FC5637C // Smoothing Surface

View File

@ -24,10 +24,12 @@ INCLUDE_DIRECTORIES(
${OMNIORB_INCLUDE_DIR}
${PTHREAD_INCLUDE_DIR}
${CAS_INCLUDE_DIRS}
${LIBXML2_INCLUDE_DIR}
${KERNEL_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/src/GEOMImpl
${PROJECT_SOURCE_DIR}/src/GEOM
${PROJECT_SOURCE_DIR}/src/GEOMAlgo
${PROJECT_SOURCE_DIR}/src/XAO
${PROJECT_BINARY_DIR}/idl
${CMAKE_CURRENT_SOURCE_DIR}
${PROJECT_BINARY_DIR}
@ -36,6 +38,7 @@ INCLUDE_DIRECTORIES(
# additional preprocessor / compiler flags
ADD_DEFINITIONS(
${CAS_DEFINITIONS}
${LIBXML2_DEFINITIONS}
${OMNIORB_DEFINITIONS}
)
@ -102,4 +105,4 @@ ADD_LIBRARY(GEOMEngine ${GEOMEngine_SOURCES})
TARGET_LINK_LIBRARIES(GEOMEngine ${_link_LIBRARIES})
INSTALL(TARGETS GEOMEngine EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS})
INSTALL(FILES ${GEOMEngine_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS})
INSTALL(FILES ${GEOMEngine_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS})

View File

@ -360,3 +360,119 @@ GEOM::ListOfLong* GEOM_IInsertOperations_i::GetAllTextures()
anIDs[i] = *anIt;
return anIDs._retn();
}
//=============================================================================
/*!
* Export a shape to XAO format
* \param shape The shape to export
* \param groups The list of groups to export
* \param fields The list of fields to export
* \param author The author of the export
* \param fileName The name of the exported file
* \return boolean indicating if export was succeful.
*/
//=============================================================================
CORBA::Boolean GEOM_IInsertOperations_i::ExportXAO(GEOM::GEOM_Object_ptr shape,
const GEOM::ListOfGO& groups, const GEOM::ListOfGO& fields,
const char* author, const char* fileName)
{
bool isGood = false;
// Set a not done flag
GetOperations()->SetNotDone();
// Get the reference shape
Handle(GEOM_Object) reference = GetObjectImpl(shape);
// Get the reference groups
int ind = 0;
std::list<Handle(GEOM_Object)> groupsObj;
for (; ind < groups.length(); ind++)
{
Handle(GEOM_Object) gobj = GetObjectImpl(groups[ind]);
if (gobj.IsNull()) return false;
groupsObj.push_back(gobj);
}
// Get the reference fields
ind = 0;
std::list<Handle(GEOM_Object)> fieldsObj;
for (; ind < fields.length(); ind++)
{
Handle(GEOM_Object) fobj = GetObjectImpl(fields[ind]);
if (fobj.IsNull()) return false;
fieldsObj.push_back(fobj);
}
if (!reference.IsNull())
{
// Export XAO
isGood = GetOperations()->ExportXAO(reference, groupsObj, fieldsObj, author, fileName);
}
return isGood;
}
//=============================================================================
/*!
* Import a shape from XAO format
* \param fileName The name of the file to import
* \param shape The imported shape
* \param subShapes The list of imported subShapes
* \param groups The list of imported groups
* \param fields The list of imported fields
* \return boolean indicating if import was succeful.
*/
//=============================================================================
CORBA::Boolean GEOM_IInsertOperations_i::ImportXAO(const char* fileName,
GEOM::GEOM_Object_out shape,
GEOM::ListOfGO_out subShapes,
GEOM::ListOfGO_out groups,
GEOM::ListOfGO_out fields)
{
GEOM::GEOM_Object_var vshape;
shape = vshape._retn();
subShapes = new GEOM::ListOfGO;
groups = new GEOM::ListOfGO;
fields = new GEOM::ListOfGO;
// Set a not done flag
GetOperations()->SetNotDone();
Handle(TColStd_HSequenceOfTransient) importedSubShapes = new TColStd_HSequenceOfTransient();
Handle(TColStd_HSequenceOfTransient) importedGroups = new TColStd_HSequenceOfTransient();
Handle(TColStd_HSequenceOfTransient) importedFields = new TColStd_HSequenceOfTransient();
Handle(GEOM_Object) hshape;
bool res = GetOperations()->ImportXAO(fileName, hshape, importedSubShapes, importedGroups, importedFields);
if (!GetOperations()->IsDone() || !res)
return false;
// parse fields
int n = importedSubShapes->Length();
subShapes->length(n);
for (int i = 1; i <= n; i++)
{
(*subShapes)[i - 1] = GetObject(Handle(GEOM_Object)::DownCast(importedSubShapes->Value(i)));
}
// parse groups
n = importedGroups->Length();
groups->length(n);
for (int i = 1; i <= n; i++)
{
(*groups)[i - 1] = GetObject(Handle(GEOM_Object)::DownCast(importedGroups->Value(i)));
}
// parse fields
n = importedFields->Length();
fields->length(n);
for (int i = 1; i <= n; i++)
{
(*fields)[i - 1] = GetObject(Handle(GEOM_Object)::DownCast(importedFields->Value(i)));
}
shape = GetObject(hshape);
return res;
}

View File

@ -72,7 +72,19 @@ class GEOM_I_EXPORT GEOM_IInsertOperations_i :
CORBA::Long& theHeight);
GEOM::ListOfLong* GetAllTextures();
CORBA::Boolean ExportXAO (GEOM::GEOM_Object_ptr shape,
const GEOM::ListOfGO& groups,
const GEOM::ListOfGO& fields,
const char* author,
const char* fileName);
CORBA::Boolean ImportXAO (const char* fileName,
GEOM::GEOM_Object_out shape,
GEOM::ListOfGO_out subShapes,
GEOM::ListOfGO_out groups,
GEOM::ListOfGO_out fields);
::GEOMImpl_IInsertOperations* GetOperations()
{ return (::GEOMImpl_IInsertOperations*)GetImpl(); }
};

View File

@ -3288,6 +3288,30 @@ GEOM::GEOM_List_ptr GEOM_Superv_i::GetObjects (GEOM::GEOM_Object_ptr theGroup)
return aListPtr->_this();
}
//=============================================================================
// ExportXAO
//=============================================================================
CORBA::Boolean GEOM_Superv_i::ExportXAO (GEOM::GEOM_Object_ptr shape,
const GEOM::ListOfGO& groups, const GEOM::ListOfGO& fields,
const char* author, const char* fileName)
{
beginService( " GEOM_Superv_i::ExportXAO" );
MESSAGE("GEOM_Superv_i::ExportXAO");
getInsOp();
CORBA::Boolean isGood = myInsOp->ExportXAO(shape, groups, fields, author, fileName);
endService( " GEOM_Superv_i::ExportXAO" );
return isGood;
}
//=============================================================================
// ImportXAO
//=============================================================================
CORBA::Boolean GEOM_Superv_i::ImportXAO (const char* fileName, GEOM::GEOM_Object_out shape,
GEOM::ListOfGO_out subShapes, GEOM::ListOfGO_out groups, GEOM::ListOfGO_out fields)
{
return false;
}
//=============================== Advanced Operations =============================
//=============================================================================
// MakePipeTShape

View File

@ -682,6 +682,15 @@ public:
GEOM::GEOM_Object_ptr GetMainShape (GEOM::GEOM_Object_ptr theGroup);
GEOM::GEOM_List_ptr GetObjects (GEOM::GEOM_Object_ptr theGroup);
//-----------------------------------------------------------//
// ImportExport Operations //
//-----------------------------------------------------------//
CORBA::Boolean ExportXAO(GEOM::GEOM_Object_ptr shape,
const GEOM::ListOfGO& groups, const GEOM::ListOfGO& fields,
const char* author, const char* fileName);
CORBA::Boolean ImportXAO(const char* fileName, GEOM::GEOM_Object_out shape,
GEOM::ListOfGO_out subShapes, GEOM::ListOfGO_out groups, GEOM::ListOfGO_out fields);
//-----------------------------------------------------------//
// Advanced Operations //
//-----------------------------------------------------------//

View File

@ -12288,6 +12288,36 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen):
RaiseIfFailed("MakeSmoothingSurface", self.AdvOp)
return anObj
## Export a shape to XAO format
# @param shape The shape to export
# @param groups The list of groups to export
# @param fields The list of fields to export
# @param author The author of the export
# @param fileName The name of the file to export
# @return boolean
#
# @ref tui_exportxao "Example"
def ExportXAO(self, shape, groups, fields, author, fileName):
res = self.InsertOp.ExportXAO(shape, groups, fields, author, fileName)
RaiseIfFailed("ExportXAO", self.InsertOp)
return res
## Import a shape from XAO format
# @param shape Shape to export
# @param fileName The name of the file to import
# @return tuple (res, shape, subShapes, groups, fields)
# res Flag indicating if the import was successful
# shape The imported shape
# subShapes The list of imported subShapes
# groups The list of imported groups
# fields The list of imported fields
#
# @ref tui_importxao "Example"
def ImportXAO(self, fileName):
res = self.InsertOp.ImportXAO(fileName)
RaiseIfFailed("ImportXAO", self.InsertOp)
return res
#@@ insert new functions before this line @@ do not remove this line @@#
# end of l4_advanced

View File

@ -0,0 +1,91 @@
# Copyright (C) 2012-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
# 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
#
INCLUDE(UseQt4Ext)
INCLUDE(${QT_USE_FILE})
# --- options ---
# additional include directories
INCLUDE_DIRECTORIES(
${QT_INCLUDE_DIRS}
${PTHREAD_INCLUDE_DIR}
${VTK_INCLUDE_DIRS}
${OMNIORB_INCLUDE_DIR}
${CAS_INCLUDE_DIRS}
${KERNEL_INCLUDE_DIRS}
${GUI_INCLUDE_DIRS}
${PROJECT_BINARY_DIR}/idl
${PROJECT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/src/OBJECT
${PROJECT_SOURCE_DIR}/src/GEOMClient
${PROJECT_SOURCE_DIR}/src/GEOMImpl
${PROJECT_SOURCE_DIR}/src/GEOMGUI
${PROJECT_SOURCE_DIR}/src/GEOMBase
${PROJECT_SOURCE_DIR}/src/DlgRef
${PROJECT_BINARY_DIR}/src/DlgRef
)
# additional preprocessor / compiler flags
ADD_DEFINITIONS(
${CAS_DEFINITIONS}
${OMNIORB_DEFINITIONS}
${QT_DEFINITIONS}
)
# libraries to link to
SET(_link_LIBRARIES
GEOMObject
GEOMClient
GEOMImpl
GEOMBase
GEOM
DlgRef
)
# --- headers ---
# header files / no moc processing
SET(ImportExportGUI_HEADERS
ImportExportGUI.h
)
# header files / to be processed by moc
SET(_moc_HEADERS
ImportExportGUI_ExportXAODlg.h
ImportExportGUI_ImportXAODlg.h
)
# --- sources ---
# sources / moc wrappings
QT4_WRAP_CPP(_moc_SOURCES ${_moc_HEADERS})
SET(ImportExportGUI_SOURCES
ImportExportGUI.cxx
ImportExportGUI_ExportXAODlg.cxx
ImportExportGUI_ImportXAODlg.cxx
${_moc_SOURCES}
)
# --- rules ---
ADD_LIBRARY(ImportExportGUI ${ImportExportGUI_SOURCES})
TARGET_LINK_LIBRARIES(ImportExportGUI ${_link_LIBRARIES})
INSTALL(TARGETS ImportExportGUI EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS})

View File

@ -0,0 +1,98 @@
// 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
// 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
#include <iostream>
#include <QDialog>
#include "GeometryGUI.h"
#include "GeometryGUI_Operations.h"
#include <GEOMBase.h>
#include <SUIT_Desktop.h>
#include <SUIT_Desktop.h>
#include <SUIT_MessageBox.h>
#include <SalomeApp_Application.h>
#include "ImportExportGUI_ExportXAODlg.h"
#include "ImportExportGUI_ImportXAODlg.h"
#include "ImportExportGUI.h"
//@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@//
//=======================================================================
// function : ImportExportGUI()
// purpose : Constructor
//=======================================================================
ImportExportGUI::ImportExportGUI(GeometryGUI* parent) :
GEOMGUI(parent)
{
}
//=======================================================================
// function : ~ImportExportGUI
// purpose : Destructor
//=======================================================================
ImportExportGUI::~ImportExportGUI()
{
}
//=======================================================================
// function : OnGUIEvent()
// purpose :
//=======================================================================
bool ImportExportGUI::OnGUIEvent(int commandId, SUIT_Desktop* parent)
{
SalomeApp_Application* app = getGeometryGUI()->getApp();
if (!app) return false;
getGeometryGUI()->EmitSignalDeactivateDialog();
QDialog* dialog = NULL;
switch (commandId)
{
case GEOMOp::OpExportXAO:
dialog = new ImportExportGUI_ExportXAODlg(getGeometryGUI(), parent);
break;
case GEOMOp::OpImportXAO:
dialog = new ImportExportGUI_ImportXAODlg(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 (dialog != NULL)
dialog->show();
return true;
}
//=====================================================================================
// EXPORTED METHODS
//=====================================================================================
extern "C"
{
#ifdef WIN32
__declspec( dllexport )
#endif
GEOMGUI* GetLibGUI(GeometryGUI* parent)
{
return new ImportExportGUI(parent);
}
}

View File

@ -0,0 +1,41 @@
// 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
// 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
//
// File : ImportExportGUI.h
// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
//
#ifndef IMPORTEXPORTGUI_H
#define IMPORTEXPORTGUI_H
#include "GEOMGUI.h"
//=================================================================================
// class : ImportExportGUI
// purpose :
//=================================================================================
class ImportExportGUI: public GEOMGUI
{
public:
ImportExportGUI(GeometryGUI* parent);
~ImportExportGUI();
bool OnGUIEvent(int commandId, SUIT_Desktop* parent);
};
#endif // IMPORTEXPORTGUI_H

View File

@ -0,0 +1,383 @@
// 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
// 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
#include <DlgRef.h>
#include <GeometryGUI.h>
#include <GEOMBase.h>
#include <SUIT_Session.h>
#include <SUIT_ResourceMgr.h>
#include <SalomeApp_Application.h>
#include <SalomeApp_Study.h>
#include <LightApp_SelectionMgr.h>
#include <QLabel>
#include <QLineEdit>
#include <QButtonGroup>
#include <QListWidget>
#include <QFileDialog>
#include <QMap>
//#include <ui_ImportExportGUI_1Sel1LineEdit2ListWidget_QTD.h>
// OCCT Includes
#include <TopoDS_Shape.hxx>
#include <TopoDS.hxx>
#include <TopExp.hxx>
#include <TColStd_IndexedMapOfInteger.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <GEOMImpl_Types.hxx>
#include "ImportExportGUI_ExportXAODlg.h"
//#include "ImportExportGUI_Widgets.h"
//=================================================================================
// Constructor
//=================================================================================
ImportExportGUI_ExportXAODlg::ImportExportGUI_ExportXAODlg(GeometryGUI* geometryGUI, QWidget* parent)
:
GEOMBase_Skeleton(geometryGUI, parent, false)
{
m_mainObj = GEOM::GEOM_Object::_nil();
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
QPixmap imageOp(resMgr->loadPixmap("GEOM", tr("ICON_DLG_EXPORTXAO")));
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();
// hide name
mainFrame()->GroupBoxName->hide();
//****************************
// Selection Group box
QGroupBox* gbxExport = new QGroupBox(parent);
QGridLayout* gridLayoutExport = new QGridLayout(gbxExport);
#ifndef Q_OS_MAC
gridLayoutExport->setSpacing(6);
gridLayoutExport->setContentsMargins(9, 9, 9, 9);
#endif
gridLayoutExport->setObjectName(QString::fromUtf8("gridLayoutExport"));
// Line 0
QLabel* lblShape = new QLabel(tr("GEOM_EXPORTXAO_EXPORTINGSHAPE"), gbxExport);
btnShapeSelect = new QPushButton(gbxExport);
btnShapeSelect->setIcon(iconSelect);
ledShape = new QLineEdit(gbxExport);
ledShape->setMinimumSize(QSize(100, 0));
int line = 0, col = 0;
gridLayoutExport->addWidget(lblShape, line, col++, 1, 1);
gridLayoutExport->addWidget(btnShapeSelect, line, col++, 1, 1);
gridLayoutExport->addWidget(ledShape, line, col++, 1, 1);
// Line 1
QLabel* lblFileName = new QLabel(tr("GEOM_EXPORTXAO_FILENAME"), gbxExport);
btnFileSelect = new QPushButton(gbxExport);
ledFileName = new QLineEdit(gbxExport);
btnFileSelect->setText("...");
line++; col = 0;
gridLayoutExport->addWidget(lblFileName, line, col++, 1, 1);
gridLayoutExport->addWidget(btnFileSelect, line, col++, 1, 1);
gridLayoutExport->addWidget(ledFileName, line, col++, 1, 1);
// Line 2
QLabel* lblAuthor = new QLabel(tr("GEOM_EXPORTXAO_AUTHOR"), gbxExport);
ledAuthor = new QLineEdit(gbxExport);
line++; col = 0;
gridLayoutExport->addWidget(lblAuthor, line, col++, 2, 1);
col++; // span
gridLayoutExport->addWidget(ledAuthor, line, col++, 1, 1);
//****************************
// Filter Group box
QGroupBox* gbxFilter = new QGroupBox(parent);
QGridLayout* gridLayoutFilter = new QGridLayout(gbxFilter);
#ifndef Q_OS_MAC
gridLayoutFilter->setSpacing(6);
gridLayoutFilter->setContentsMargins(9, 9, 9, 9);
#endif
gridLayoutFilter->setObjectName(QString::fromUtf8("gbxFilter"));
// Line 0
QLabel* lblGroups = new QLabel(tr("GEOM_EXPORTXAO_LGROUPS"), gbxFilter);
QLabel* lblFields = new QLabel(tr("GEOM_EXPORTXAO_LFIELDS"), gbxFilter);
line = 0, col = 0;
gridLayoutFilter->addWidget(lblGroups, line, col++, 1, 1);
gridLayoutFilter->addWidget(lblFields, line, col++, 1, 1);
// Line 1
lstGroups = new QListWidget(gbxFilter);
lstGroups->setSelectionMode(QAbstractItemView::ExtendedSelection);
lstFields = new QListWidget(gbxFilter);
lstFields ->setSelectionMode(QAbstractItemView::ExtendedSelection);
line++; col = 0;
gridLayoutFilter->addWidget(lstGroups, line, col++, 1, 1);
gridLayoutFilter->addWidget(lstFields, line, col++, 1, 1);
//****************************
QVBoxLayout* layout = new QVBoxLayout(centralWidget());
layout->setMargin(0);
layout->setSpacing(6);
layout->addWidget(gbxExport);
layout->addWidget(gbxFilter);
// set help
setHelpFileName("create_exportxao_page.html");
Init();
}
//=================================================================================
// Destructor
//=================================================================================
ImportExportGUI_ExportXAODlg::~ImportExportGUI_ExportXAODlg()
{
// no need to delete child widgets, Qt does it all for us
}
//=================================================================================
// function : Init()
// purpose :
//=================================================================================
void ImportExportGUI_ExportXAODlg::Init()
{
// 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()));
connect(btnShapeSelect, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
connect(((SalomeApp_Application*) (SUIT_Session::session()->activeApplication()))->selectionMgr(),
SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
connect(btnFileSelect, SIGNAL(clicked()), this, SLOT(btnFileSelectClicked()));
initName(tr("GEOM_EXPORTXAO"));
SelectionIntoArgument();
}
//=================================================================================
// function : processObject()
// purpose : Fill dialog fields in accordance with myObj
//=================================================================================
void ImportExportGUI_ExportXAODlg::processObject()
{
lstGroups->clear();
lstFields->clear();
m_groups.clear();
m_fields.clear();
if (m_mainObj->_is_nil())
{
ledShape->setText("");
}
else
{
ledShape->setText(GEOMBase::GetName(m_mainObj));
GEOM::GEOM_IShapesOperations_var shapeOp = getGeomEngine()->GetIShapesOperations(getStudyId());
// add groups names
GEOM::ListOfGO_var groups = shapeOp->GetExistingSubObjects(m_mainObj, true);
for (int i = 0, n = groups->length(); i < n; i++)
{
QListWidgetItem* item = new QListWidgetItem();
item->setData(Qt::UserRole, QVariant(i));
item->setText(GEOMBase::GetName(groups[i]));
lstGroups->addItem(item);
m_groups.append(GEOM::GeomObjPtr(groups[i].in()));
}
lstGroups->sortItems(Qt::AscendingOrder);
// TODO: add fields
}
}
//=================================================================================
// function : ClickOnOk()
// purpose :
//=================================================================================
void ImportExportGUI_ExportXAODlg::ClickOnOk()
{
if (ClickOnApply())
ClickOnCancel();
}
//=================================================================================
// function : ClickOnApply()
// purpose :
//=================================================================================
bool ImportExportGUI_ExportXAODlg::ClickOnApply()
{
if (!onAccept())
return false;
initName();
return true;
}
//=================================================================================
// function : SelectionIntoArgument()
// purpose : Called when selection as changed or other case
//=================================================================================
void ImportExportGUI_ExportXAODlg::SelectionIntoArgument()
{
m_mainObj = GEOM::GEOM_Object::_nil();
LightApp_SelectionMgr* selMgr = myGeomGUI->getApp()->selectionMgr();
SALOME_ListIO selList;
selMgr->selectedObjects(selList);
if (selList.Extent() == 1)
{
m_mainObj = GEOMBase::ConvertIOinGEOMObject(selList.First());
}
processObject();
}
//=================================================================================
// function : SetEditCurrentArgument()
// purpose :
//=================================================================================
void ImportExportGUI_ExportXAODlg::SetEditCurrentArgument()
{
ledShape->setFocus();
myEditCurrentArgument = ledShape;
SelectionIntoArgument();
}
//=================================================================================
// function : btnFileSelectClicked()
// purpose :
//=================================================================================
void ImportExportGUI_ExportXAODlg::btnFileSelectClicked()
{
QString selFile = QFileDialog::getSaveFileName(this, tr("GEOM_SELECT_EXPORT_XAO"),
QString(), tr("XAO_FILES"));
if (!selFile.isEmpty())
{
ledFileName->setText(selFile);
}
}
//=================================================================================
// function : ActivateThisDialog()
// purpose :
//=================================================================================
void ImportExportGUI_ExportXAODlg::ActivateThisDialog()
{
GEOMBase_Skeleton::ActivateThisDialog();
}
//=================================================================================
// function : enterEvent [REDEFINED]
// purpose :
//=================================================================================
void ImportExportGUI_ExportXAODlg::enterEvent(QEvent*)
{
if (!mainFrame()->GroupConstructors->isEnabled())
ActivateThisDialog();
}
//=================================================================================
// function : createOperation
// purpose :
//=================================================================================
GEOM::GEOM_IOperations_ptr ImportExportGUI_ExportXAODlg::createOperation()
{
return getGeomEngine()->GetIInsertOperations(getStudyId());
}
//=================================================================================
// function : isValid
// purpose :
//=================================================================================
bool ImportExportGUI_ExportXAODlg::isValid(QString& msg)
{
// check shape
if (ledShape->text().isEmpty())
return false;
// check file name
if (ledFileName->text().isEmpty())
return false;
return true;
}
//=================================================================================
// function : execute
// purpose :
//=================================================================================
bool ImportExportGUI_ExportXAODlg::execute(ObjectList& objects)
{
bool res = false;
QString author = ledAuthor->text();
QString fileName = ledFileName->text();
// get selected groups
QList<QListWidgetItem*> selGroups = lstGroups->selectedItems();
GEOM::ListOfGO_var groups = new GEOM::ListOfGO();
groups->length(selGroups.count());
int i = 0;
for (QList<QListWidgetItem*>::iterator it = selGroups.begin(); it != selGroups.end(); ++it)
{
QListWidgetItem* item = (*it);
int index = item->data(Qt::UserRole).toInt();
groups[i++] = m_groups[index].copy();
}
// get selected fields
QList<QListWidgetItem*> selFields = lstFields->selectedItems();
GEOM::ListOfGO_var fields = new GEOM::ListOfGO();
fields->length(m_fields.count());
for (QList<QListWidgetItem*>::iterator it = selFields.begin(); it != selFields.end(); ++it)
{
QListWidgetItem* item = (*it);
int index = item->data(Qt::UserRole).toInt();
fields[i++] = m_fields[index].copy();
}
// call engine function
GEOM::GEOM_IInsertOperations_var ieOp = GEOM::GEOM_IInsertOperations::_narrow(getOperation());
res = ieOp->ExportXAO(m_mainObj, groups, fields,
author.toStdString().c_str(),
fileName.toStdString().c_str());
return res;
}

View File

@ -0,0 +1,76 @@
// 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
// 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
#ifndef IMPORTEXPORTGUI_EXPORTXAODLG_H
#define IMPORTEXPORTGUI_EXPORTXAODLG_H
#include <GEOMBase_Skeleton.h>
#include <GEOM_GenericObjPtr.h>
class QLineEdit;
class QButtonGroup;
class QListWidget;
//class ImportExportGUI_1Sel1LineEdit2ListWidget;
//=================================================================================
// class : ImportExportGUI_ExportXAODlg
// purpose :
//=================================================================================
class ImportExportGUI_ExportXAODlg: public GEOMBase_Skeleton
{
Q_OBJECT
public:
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&);
private:
void Init();
void enterEvent(QEvent*);
void processObject();
private:
GEOM::GEOM_Object_var m_mainObj;
QList<GEOM::GeomObjPtr> m_groups;
QList<GEOM::GeomObjPtr> m_fields;
QLineEdit* ledShape;
QLineEdit* ledFileName;
QLineEdit* ledAuthor;
QListWidget* lstGroups;
QListWidget* lstFields;
QPushButton* btnShapeSelect;
QPushButton* btnFileSelect;
private slots:
void ClickOnOk();
bool ClickOnApply();
void ActivateThisDialog();
void LineEditReturnPressed();
void SelectionIntoArgument();
void SetEditCurrentArgument();
void btnFileSelectClicked();
};
#endif // IMPORTEXPORTGUI_EXPORTXAODLG_H

View File

@ -0,0 +1,266 @@
// 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
// 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
#include <DlgRef.h>
#include <GeometryGUI.h>
#include <GEOMBase.h>
#include <SUIT_Session.h>
#include <SUIT_ResourceMgr.h>
#include <SalomeApp_Application.h>
#include <SalomeApp_Study.h>
#include <LightApp_SelectionMgr.h>
#include <QLabel>
#include <QLineEdit>
#include <QButtonGroup>
#include <QListWidget>
#include <QFileDialog>
#include <QMap>
// OCCT Includes
#include <TopoDS_Shape.hxx>
#include <TopoDS.hxx>
#include <TopExp.hxx>
#include <TColStd_IndexedMapOfInteger.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <GEOMImpl_Types.hxx>
#include "ImportExportGUI_ImportXAODlg.h"
//=================================================================================
// Constructor
//=================================================================================
ImportExportGUI_ImportXAODlg::ImportExportGUI_ImportXAODlg(GeometryGUI* geometryGUI, QWidget* parent)
:
GEOMBase_Skeleton(geometryGUI, parent, false)
{
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
QPixmap imageOp(resMgr->loadPixmap("GEOM", tr("ICON_DLG_IMPORTXAO")));
QPixmap iconSelect(resMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
setWindowTitle(tr("GEOM_IMPORTXAO_TITLE"));
/***************************************************************/
mainFrame()->GroupConstructors->setTitle(tr("GEOM_IMPORTXAO_TITLE"));
mainFrame()->RadioButton1->setIcon(imageOp);
mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
mainFrame()->RadioButton2->close();
mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
mainFrame()->RadioButton3->close();
// hide name
mainFrame()->GroupBoxName->hide();
//****************************
// Selection Group box
QGroupBox* gbxExport = new QGroupBox(parent);
QGridLayout* gridLayoutExport = new QGridLayout(gbxExport);
#ifndef Q_OS_MAC
gridLayoutExport->setSpacing(6);
gridLayoutExport->setContentsMargins(9, 9, 9, 9);
#endif
gridLayoutExport->setObjectName(QString::fromUtf8("gridLayoutExport"));
int line = 0, col = 0;
QLabel* lblFileName = new QLabel(tr("GEOM_IMPORTXAO_FILENAME"), gbxExport);
btnFileSelect = new QPushButton(gbxExport);
ledFileName = new QLineEdit(gbxExport);
btnFileSelect->setText("...");
line++; col = 0;
gridLayoutExport->addWidget(lblFileName, line, col++, 1, 1);
gridLayoutExport->addWidget(btnFileSelect, line, col++, 1, 1);
gridLayoutExport->addWidget(ledFileName, line, col++, 1, 1);
//****************************
QVBoxLayout* layout = new QVBoxLayout(centralWidget());
layout->setMargin(0);
layout->setSpacing(6);
layout->addWidget(gbxExport);
// set help
setHelpFileName("create_importxao_page.html");
Init();
}
//=================================================================================
// Destructor
//=================================================================================
ImportExportGUI_ImportXAODlg::~ImportExportGUI_ImportXAODlg()
{
// no need to delete child widgets, Qt does it all for us
}
//=================================================================================
// function : Init()
// purpose :
//=================================================================================
void ImportExportGUI_ImportXAODlg::Init()
{
// Signal/slot connections
connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
connect(btnFileSelect, SIGNAL(clicked()), this, SLOT(btnFileSelectClicked()));
initName(tr("GEOM_IMPORTXAO"));
//SelectionIntoArgument();
}
//=================================================================================
// function : ClickOnOk()
// purpose :
//=================================================================================
void ImportExportGUI_ImportXAODlg::ClickOnOk()
{
if (ClickOnApply())
ClickOnCancel();
}
//=================================================================================
// function : ClickOnApply()
// purpose :
//=================================================================================
bool ImportExportGUI_ImportXAODlg::ClickOnApply()
{
if (!onAccept())
return false;
initName();
return true;
}
//=================================================================================
// function : btnFileSelectClicked()
// purpose :
//=================================================================================
void ImportExportGUI_ImportXAODlg::btnFileSelectClicked()
{
QString selFile = QFileDialog::getOpenFileName(this, tr("GEOM_SELECT_EXPORT_XAO"),
QString(), tr("XAO_FILES"));
if (!selFile.isEmpty())
{
ledFileName->setText(selFile);
}
}
//=================================================================================
// function : ActivateThisDialog()
// purpose :
//=================================================================================
void ImportExportGUI_ImportXAODlg::ActivateThisDialog()
{
GEOMBase_Skeleton::ActivateThisDialog();
}
//=================================================================================
// function : enterEvent [REDEFINED]
// purpose :
//=================================================================================
void ImportExportGUI_ImportXAODlg::enterEvent(QEvent*)
{
if (!mainFrame()->GroupConstructors->isEnabled())
ActivateThisDialog();
}
//=================================================================================
// function : createOperation
// purpose :
//=================================================================================
GEOM::GEOM_IOperations_ptr ImportExportGUI_ImportXAODlg::createOperation()
{
return getGeomEngine()->GetIInsertOperations(getStudyId());
}
//=================================================================================
// function : isValid
// purpose :
//=================================================================================
bool ImportExportGUI_ImportXAODlg::isValid(QString& msg)
{
// check file name
if (ledFileName->text().isEmpty())
return false;
return true;
}
//=================================================================================
// function : execute
// purpose :
//=================================================================================
bool ImportExportGUI_ImportXAODlg::execute(ObjectList& objects)
{
bool res = false;
QString fileName = ledFileName->text();
GEOM::GEOM_Object_var shape;
GEOM::ListOfGO_var groups, fields, subShapes;
GEOM::GEOM_IInsertOperations_var ieOp = GEOM::GEOM_IInsertOperations::_narrow(getOperation());
res = ieOp->ImportXAO(fileName.toStdString().c_str(), shape, subShapes, groups, fields);
if (!shape->_is_nil())
{
m_mainShape = shape;
objects.push_back(shape._retn());
}
else
{
m_mainShape = NULL;
}
for (int i = 0; i < subShapes->length(); i++)
{
objects.push_back(GEOM::GEOM_Object::_duplicate(subShapes[i]));
}
for (int i = 0; i < groups->length(); i++)
{
objects.push_back(GEOM::GEOM_Object::_duplicate(groups[i]));
}
for (int i = 0; i < fields->length(); i++)
{
objects.push_back(GEOM::GEOM_Object::_duplicate(fields[i]));
}
return res;
}
GEOM::GEOM_Object_ptr ImportExportGUI_ImportXAODlg::getFather(GEOM::GEOM_Object_ptr object)
{
GEOM::GEOM_Object_var fatherObj;
if (object->GetType() != GEOM_IMPORT && m_mainShape != NULL)
{
//GEOM::GEOM_IGroupOperations_var groupOper = getGeomEngine()->GetIGroupOperations(getStudyId());
//fatherObj = groupOper->GetMainShape(object);
fatherObj = m_mainShape;
}
return fatherObj._retn();
}
QString ImportExportGUI_ImportXAODlg::getObjectName(GEOM::GEOM_Object_ptr object) const
{
if (object->_is_nil())
return QString::null;
return object->GetName();
}

View File

@ -0,0 +1,66 @@
// 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
// 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
#ifndef IMPORTEXPORTGUI_IMPORTXAODLG_H
#define IMPORTEXPORTGUI_IMPORTXAODLG_H
#include <GEOMBase_Skeleton.h>
#include <GEOM_GenericObjPtr.h>
class QLineEdit;
class QButtonGroup;
class QListWidget;
//=================================================================================
// class : ImportExportGUI_ImportXAODlg
// purpose :
//=================================================================================
class ImportExportGUI_ImportXAODlg: public GEOMBase_Skeleton
{
Q_OBJECT
public:
ImportExportGUI_ImportXAODlg(GeometryGUI*, QWidget* = 0);
~ImportExportGUI_ImportXAODlg();
protected:
// redefined from GEOMBase_Helper
virtual GEOM::GEOM_IOperations_ptr createOperation();
virtual bool isValid(QString&);
virtual bool execute(ObjectList&);
virtual GEOM::GEOM_Object_ptr getFather(GEOM::GEOM_Object_ptr object);
virtual QString getObjectName(GEOM::GEOM_Object_ptr object) const;
private:
void Init();
void enterEvent(QEvent*);
private:
QLineEdit* ledFileName;
QPushButton* btnFileSelect;
GEOM::GEOM_Object_var m_mainShape;
private slots:
void ClickOnOk();
bool ClickOnApply();
void ActivateThisDialog();
void LineEditReturnPressed();
void btnFileSelectClicked();
};
#endif // IMPORTEXPORTGUI_EXPORTXAODLG_H

97
src/XAO/CMakeLists.txt Normal file
View File

@ -0,0 +1,97 @@
# Copyright (C) 2012-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
# 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
#
IF(SALOME_BUILD_TESTS)
ADD_SUBDIRECTORY(tests)
ENDIF(SALOME_BUILD_TESTS)
# --- options ---
# additional include directories
INCLUDE_DIRECTORIES(
${PTHREAD_INCLUDE_DIR}
${LIBXML2_INCLUDE_DIR}
${CAS_INCLUDE_DIRS}
)
# additional preprocessor / compiler flags
ADD_DEFINITIONS(
${LIBXML2_DEFINITIONS}
${CAS_DEFINITIONS}
)
# libraries to link to
SET(_link_LIBRARIES
${PTHREAD_LIBRARIES}
${LIBXML2_LIBRARIES}
${CAS_TKBRep} ${CAS_TKTopAlgo}
)
# --- headers ---
SET(XAO_HEADERS
XAO_BooleanField.hxx
XAO_BooleanStep.hxx
XAO_BrepGeometry.hxx
XAO_DoubleField.hxx
XAO_DoubleStep.hxx
XAO_Exception.hxx
XAO_Field.hxx
XAO_GeometricElement.hxx
XAO_Geometry.hxx
XAO_Group.hxx
XAO_IntegerField.hxx
XAO_IntegerStep.hxx
XAO_Step.hxx
XAO_StringField.hxx
XAO_StringStep.hxx
XAO_Xao.hxx
XAO_XaoExporter.hxx
XAO_XaoUtils.hxx
)
# --- sources ---
SET(XAO_SOURCES
XAO_BooleanField.cxx
XAO_BooleanStep.cxx
XAO_BrepGeometry.cxx
XAO_DoubleField.cxx
XAO_DoubleStep.cxx
XAO_Field.cxx
XAO_GeometricElement.cxx
XAO_Geometry.cxx
XAO_Group.cxx
XAO_IntegerField.cxx
XAO_IntegerStep.cxx
XAO_Step.cxx
XAO_StringField.cxx
XAO_StringStep.cxx
XAO_Xao.cxx
XAO_XaoExporter.cxx
XAO_XaoUtils.cxx
)
# --- rules ---
ADD_LIBRARY(XAO ${XAO_SOURCES})
TARGET_LINK_LIBRARIES(XAO ${_link_LIBRARIES})
INSTALL(TARGETS XAO EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS})
INSTALL(FILES ${XAO_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS})

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 "XAO_BooleanField.hxx"
#include "XAO_BooleanStep.hxx"
#include "XAO_XaoUtils.hxx"
using namespace XAO;
BooleanField::BooleanField(const XAO::Dimension& dimension,
const int& nbElements, const int& nbComponents, const std::string& name)
: Field(dimension, nbElements, nbComponents, name)
{
}
Step* BooleanField::addNewStep(const int& step)
throw (XAO_Exception)
{
return addStep(step, 0);
}
BooleanStep* BooleanField::addStep(const int& step)
throw (XAO_Exception)
{
return addStep(step, 0);
}
BooleanStep* BooleanField::addStep(const int& step, const int& stamp)
throw (XAO_Exception)
{
if (hasStep(step))
throw XAO_Exception(MsgBuilder() << "Step with number " << step << " already exists.");
BooleanStep* bstep = new BooleanStep(step, stamp, m_nbElements, m_nbComponents);
m_steps.push_back(bstep);
return bstep;
}
BooleanStep* BooleanField::getStep(const int& index)
throw (XAO_Exception)
{
checkStepIndex(index);
return (BooleanStep*)m_steps[index];
}

View File

@ -0,0 +1,77 @@
// 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_BOOLEANFIELD_HXX__
#define __XAO_BOOLEANFIELD_HXX__
#include <string>
#include "XAO_XaoUtils.hxx"
#include "XAO_Field.hxx"
#include "XAO_BooleanStep.hxx"
namespace XAO
{
/**
* @class BooleanField
* Represents a field with boolean values.
*/
class BooleanField : public Field
{
public:
/**
* Constructor.
* @param dimension the dimension of the field.
* @param nbElements the number of elements.
* @param nbComponents the number of components.
* @param name the name of the field.
*/
BooleanField(const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents, const std::string& name);
virtual const XAO::Type getType() { return XAO::BOOLEAN; }
virtual Step* addNewStep(const int& step) throw (XAO_Exception);
/**
* Adds a new step.
* @param step the number of the step.
* @return the newly created step.
*/
BooleanStep* addStep(const int& step) throw (XAO_Exception);
/**
* Adds a new step.
* @param step the number of the step.
* @param stamp the stamp of the step.
* @return the newly created step.
*/
BooleanStep* addStep(const int& step, const int& stamp)
throw (XAO_Exception);
/**
* Gets the step of given index.
* @param index the index.
* @return the step for the given index.
*/
BooleanStep* getStep(const int& index) throw (XAO_Exception);
};
}
#endif /* __XAO_BOOLEANFIELD_HXX__ */

148
src/XAO/XAO_BooleanStep.cxx Normal file
View File

@ -0,0 +1,148 @@
// 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 "XAO_BooleanStep.hxx"
#include "XAO_XaoUtils.hxx"
using namespace XAO;
BooleanStep::BooleanStep(const int& step, const int& stamp, const int& nbElements, const int& nbComponents)
{
m_nbElements = nbElements;
m_nbComponents = nbComponents;
m_step = step;
m_stamp = stamp;
m_values.reserve(m_nbElements);
for (int i = 0; i < m_nbElements; ++i)
{
std::vector<bool> row;
row.reserve(m_nbComponents);
for (int j = 0; j < m_nbComponents; ++j)
row.push_back(false);
m_values.push_back(row);
}
}
std::vector<bool> BooleanStep::getValues()
{
std::vector<bool> result;
result.reserve(m_nbElements * m_nbComponents);
std::vector< std::vector<bool> >::iterator it;
for (it = m_values.begin(); it != m_values.end(); ++it)
{
std::vector<bool> eltValues = *it;
result.insert(result.end(), eltValues.begin(), eltValues.end());
}
return result;
}
std::vector<bool> BooleanStep::getElement(const int& element)
throw (XAO_Exception)
{
checkElementIndex(element);
std::vector<bool> result(m_values[element]);
return result;
}
std::vector<bool> BooleanStep::getComponent(const int& component)
throw (XAO_Exception)
{
checkComponentIndex(component);
std::vector<bool> result;
result.reserve(m_nbElements);
std::vector< std::vector<bool> >::iterator it;
for (it = m_values.begin(); it != m_values.end(); ++it)
{
std::vector<bool> eltValues = *it;
result.push_back(eltValues[component]);
}
return result;
}
const bool BooleanStep::getValue(const int& element, const int& component)
throw (XAO_Exception)
{
checkElementIndex(element);
checkComponentIndex(component);
return m_values[element][component];
}
const std::string BooleanStep::getStringValue(const int& element, const int& component)
throw (XAO_Exception)
{
return XaoUtils::booleanToString(getValue(element, component));
}
void BooleanStep::setValues(const std::vector<bool>& values)
throw (XAO_Exception)
{
checkNbValues((int)values.size());
for (int i = 0; i < m_nbElements; ++i)
{
for (int j = 0; j < m_nbComponents; ++j)
{
m_values[i][j] = values[i * m_nbComponents + j];
}
}
}
void BooleanStep::setElement(const int& element, const std::vector<bool>& elements)
throw (XAO_Exception)
{
checkElementIndex(element);
checkNbComponents(elements.size());
for (int i = 0; i < m_nbComponents; ++i)
m_values[element][i] = elements[i];
}
void BooleanStep::setComponent(const int& component, const std::vector<bool>& components)
throw (XAO_Exception)
{
checkComponentIndex(component);
checkNbElements(components.size());
for (int i = 0; i < m_nbElements; ++i)
m_values[i][component] = components[i];
}
void BooleanStep::setValue(const int& element, const int& component, const bool& value)
throw (XAO_Exception)
{
checkElementIndex(element);
checkComponentIndex(component);
m_values[element][component] = value;
}
void BooleanStep::setStringValue(const int& element, const int& component, const std::string& value)
throw (XAO_Exception)
{
setValue(element, component, XaoUtils::stringToBoolean(value));
}

114
src/XAO/XAO_BooleanStep.hxx Normal file
View File

@ -0,0 +1,114 @@
// 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_BOOLEANSTEP_HXX__
#define __XAO_BOOLEANSTEP_HXX__
#include <vector>
#include "XAO_XaoUtils.hxx"
#include "XAO_Step.hxx"
namespace XAO
{
/**
* @class BooleanStep
* Step with boolean values.
*/
class BooleanStep : public Step
{
public:
/**
* Constructor.
* @param step the step number.
* @param stamp the stamp of the step.
* @param nbElements the number elements of the geometry.
* @param nbComponents the number of components of the field.
*/
BooleanStep(const int& step, const int& stamp, const int& nbElements, const int& nbComponents);
virtual const XAO::Type getType() { return XAO::BOOLEAN; }
/**
* Gets all the values in a vector by elements and by components.
* @return a vector containing all the values.
*/
std::vector<bool> getValues();
/**
* Gets all the values for an element.
* @param element the index of the element to get.
* @return a vector containing all the values for the given element.
*/
std::vector<bool> getElement(const int& element) throw (XAO_Exception);
/**
* Gets all the values for a component.
* @param component the index of the component to get.
* @return a vector containing all the values for the given component.
*/
std::vector<bool> getComponent(const int& component) throw (XAO_Exception);
/**
* Gets a value for an element and a component.
* @param element the index of the element.
* @param component the index of the component.
* @return the value.
*/
const bool getValue(const int& element, const int& component) throw (XAO_Exception);
/**
* Sets all the values from a list.
* @param values the list of values to set.
*/
void setValues(const std::vector<bool>& values) throw (XAO_Exception);
/**
* Sets the values for an element.
* @param element the index of the element to set.
* @param elements the values to set.
*/
void setElement(const int& element, const std::vector<bool>& elements) throw (XAO_Exception);
/**
* Sets the values for a component.
* @param component the index of the component to set.
* @param components the values to set.
*/
void setComponent(const int& component, const std::vector<bool>& components) throw (XAO_Exception);
/**
* Sets the value for an element and a component.
* @param element the index of the element.
* @param component the index of the component.
* @param value the value.
*/
void setValue(const int& element, const int& component, const bool& value) throw (XAO_Exception);
virtual const std::string getStringValue(const int& element, const int& component) throw (XAO_Exception);
virtual void setStringValue(const int& element, const int& component, const std::string& value) throw (XAO_Exception);
private:
std::vector< std::vector<bool> > m_values;
};
}
#endif /* __XAO_BOOLEANSTEP_HXX__ */

View File

@ -0,0 +1,401 @@
// 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 <cassert>
#include <Standard_TypeMismatch.hxx>
#include <BRepTools.hxx>
#include <BRep_Builder.hxx>
#include <TopAbs.hxx>
#include <TopTools_MapOfShape.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
#include <GProp_GProps.hxx>
#include <BRepGProp.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Vertex.hxx>
#include "XAO_BrepGeometry.hxx"
#include "XAO_XaoUtils.hxx"
using namespace XAO;
BrepGeometry::BrepGeometry() : Geometry("")
{
}
BrepGeometry::BrepGeometry(const std::string& name) : Geometry(name)
{
}
const std::string BrepGeometry::getShapeString()
{
std::ostringstream streamShape;
BRepTools::Write(m_shape, streamShape);
std::string data = streamShape.str();
char* res = new char[data.size()];
strcpy(res, data.c_str());
return res;
}
void BrepGeometry::setShapeString(const std::string& shape)
{
std::istringstream streamBrep(shape.c_str());
BRep_Builder builder;
BRepTools::Read(m_shape, streamBrep, builder);
initIds();
}
TopoDS_Shape BrepGeometry::getTopoDS_Shape()
{
return m_shape;
}
void BrepGeometry::setTopoDS_Shape(const TopoDS_Shape& shape)
{
m_shape = shape;
initIds();
}
void BrepGeometry::initIds()
{
// intialization of Ids
initListIds(TopAbs_VERTEX, m_vertices);
initListIds(TopAbs_EDGE, m_edges);
initListIds(TopAbs_FACE, m_faces);
initListIds(TopAbs_SOLID, m_solids);
}
void BrepGeometry::initListIds(const TopAbs_ShapeEnum& shapeType, GeometricElementList& eltList)
{
TopTools_MapOfShape mapShape;
TopTools_ListOfShape listShape;
int nbElt = 0;
TopExp_Explorer exp(m_shape, shapeType);
for (; exp.More(); exp.Next())
{
if (mapShape.Add(exp.Current()))
{
listShape.Append(exp.Current());
nbElt++;
}
}
if (listShape.IsEmpty())
return;
TopTools_IndexedMapOfShape indices;
TopExp::MapShapes(m_shape, indices);
eltList.setSize(nbElt);
TopTools_ListIteratorOfListOfShape itSub(listShape);
for (int index = 0; itSub.More(); itSub.Next(), ++index)
{
TopoDS_Shape value = itSub.Value();
int ref = indices.FindIndex(value);
eltList.setReference(index, XaoUtils::intToString(ref));
}
}
TopoDS_Shape BrepGeometry::getSubShape(const TopoDS_Shape& mainShape, const TopAbs_ShapeEnum& shapeType, const int& shapeIndex)
throw (XAO_Exception)
{
TopTools_MapOfShape mapShape;
TopTools_ListOfShape listShape;
TopExp_Explorer exp(mainShape, shapeType);
for (; exp.More(); exp.Next())
{
if (mapShape.Add(exp.Current()))
listShape.Append(exp.Current());
}
if (!listShape.IsEmpty())
{
TopTools_ListIteratorOfListOfShape itSub(listShape);
for (int index = 0; itSub.More(); itSub.Next(), ++index)
{
if (shapeIndex == index)
{
TopoDS_Shape value = itSub.Value();
return value;
}
}
}
throw XAO_Exception(MsgBuilder() << "Shape with reference [" << shapeIndex << "] not found.");
}
// -----------------------------
const int BrepGeometry::countGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType)
{
int res = 0;
TopExp_Explorer exp(shape, shapeType);
for (; exp.More(); exp.Next())
res++;
return res;
}
std::vector<int> BrepGeometry::getGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType, const XAO::Dimension& dim)
{
std::vector<int> indexList;
TopTools_MapOfShape mapShape;
TopTools_ListOfShape listShape;
TopExp_Explorer exp(shape, shapeType);
for (; exp.More(); exp.Next())
{
if (mapShape.Add(exp.Current()))
listShape.Append(exp.Current());
}
if (!listShape.IsEmpty())
{
// use the shape of the geometry for the indices
TopTools_IndexedMapOfShape indices;
TopExp::MapShapes(m_shape, indices);
TopTools_ListIteratorOfListOfShape itSub(listShape);
for (int index = 0; itSub.More(); itSub.Next(), ++index)
{
TopoDS_Shape value = itSub.Value();
int id = indices.FindIndex(value);
indexList.push_back(findElement(dim, id));
}
}
return indexList;
}
void BrepGeometry::getEdgeVertices(const int& edgeIndex, int& vertexA, int& vertexB)
{
TopoDS_Shape edge = getSubShape(m_shape, TopAbs_EDGE, edgeIndex);
std::vector<int> vertices = getGeometricalElements(edge, TopAbs_VERTEX, XAO::VERTEX);
assert(vertices.size() == 2);
vertexA = vertices[0];
vertexB = vertices[1];
}
const int BrepGeometry::countFaceWires(const int& faceIndex)
{
TopoDS_Shape face = getSubShape(m_shape, TopAbs_FACE, faceIndex);
return countGeometricalElements(face, TopAbs_WIRE);
}
std::vector<int> BrepGeometry::getFaceEdges(const int& faceIndex, const int& wireIndex)
{
// get the face
TopoDS_Shape face = getSubShape(m_shape, TopAbs_FACE, faceIndex);
// get the wire
TopoDS_Shape wire = getSubShape(face, TopAbs_WIRE, wireIndex);
return getGeometricalElements(wire, TopAbs_EDGE, XAO::EDGE);
}
const int BrepGeometry::countSolidShells(const int& solidIndex)
{
TopoDS_Shape solid = getSubShape(m_shape, TopAbs_SOLID, solidIndex);
return countGeometricalElements(solid, TopAbs_SHELL);
}
std::vector<int> BrepGeometry::getSolidFaces(const int& solidIndex, const int& shellIndex)
{
TopoDS_Shape solid = getSubShape(m_shape, TopAbs_SOLID, solidIndex);
TopoDS_Shape shell = getSubShape(solid, TopAbs_SHELL, shellIndex);
return getGeometricalElements(shell, TopAbs_FACE, XAO::FACE);
}
void BrepGeometry::getVertexXYZ(const int& vertexIndex, double& xCoord, double& yCoord, double& zCoord)
throw (XAO_Exception)
{
xCoord = 0.;
yCoord = 0.;
zCoord = 0.;
TopoDS_Shape vertex = getSubShape(m_shape, TopAbs_VERTEX, vertexIndex);
if (vertex.ShapeType() != TopAbs_VERTEX)
throw XAO_Exception(MsgBuilder() << "Shape " << vertexIndex<< " is not a point.");
TopoDS_Vertex point = TopoDS::Vertex(vertex);
if (!point.IsNull())
{
gp_Pnt aPnt = BRep_Tool::Pnt(point);
xCoord = aPnt.X();
yCoord = aPnt.Y();
zCoord = aPnt.Z();
}
}
// -----------------------------
const double BrepGeometry::getEdgeLength(const int& edgeIndex)
{
TopoDS_Shape edge = getSubShape(m_shape, TopAbs_EDGE, edgeIndex);
GProp_GProps system;
BRepGProp::LinearProperties(edge, system);
return system.Mass();
}
const double BrepGeometry::getFaceArea(const int& faceIndex)
{
TopoDS_Shape face = getSubShape(m_shape, TopAbs_FACE, faceIndex);
GProp_GProps system;
BRepGProp::SurfaceProperties(face, system);
return system.Mass();
}
const double BrepGeometry::getSolidVolume(const int& solidIndex)
{
TopoDS_Shape solid = getSubShape(m_shape, TopAbs_SOLID, solidIndex);
GProp_GProps system;
BRepGProp::VolumeProperties(solid, system);
return system.Mass();
}
// -----------------------------
const int BrepGeometry::getVertexID(const int& index)
{
return XaoUtils::stringToInt(getVertexReference(index));
}
const int BrepGeometry::getEdgeID(const int& index)
{
return XaoUtils::stringToInt(getEdgeReference(index));
}
const int BrepGeometry::getFaceID(const int& index)
{
return XaoUtils::stringToInt(getFaceReference(index));
}
const int BrepGeometry::getSolidID(const int& index)
{
return XaoUtils::stringToInt(getSolidReference(index));
}
// -----------------------------
void BrepGeometry::setVertexID(const int& index, const int& id)
{
setVertexReference(index, XaoUtils::intToString(id));
}
void BrepGeometry::setEdgeID(const int& index, const int& id)
{
setEdgeReference(index, XaoUtils::intToString(id));
}
void BrepGeometry::setFaceID(const int& index, const int& id)
{
setEdgeReference(index, XaoUtils::intToString(id));
}
void BrepGeometry::setSolidID(const int& index, const int& id)
{
setEdgeReference(index, XaoUtils::intToString(id));
}
// -----------------------------
const int BrepGeometry::findElement(const XAO::Dimension& dim, const int& id)
throw (XAO_Exception)
{
if (dim == XAO::VERTEX)
return findVertex(id);
if (dim == XAO::EDGE)
return findEdge(id);
if (dim == XAO::FACE)
return findFace(id);
if (dim == XAO::SOLID)
return findSolid(id);
throw XAO_Exception(MsgBuilder() << "Unknown Dimension: " << dim);
}
const int BrepGeometry::findVertex(const int& id)
{
return getVertexIndexByReference(XaoUtils::intToString(id));
}
const int BrepGeometry::findEdge(const int& id)
{
return getEdgeIndexByReference(XaoUtils::intToString(id));
}
const int BrepGeometry::findFace(const int& id)
{
return getFaceIndexByReference(XaoUtils::intToString(id));
}
const int BrepGeometry::findSolid(const int& id)
{
return getSolidIndexByReference(XaoUtils::intToString(id));
}
// -----------------------------
const std::string BrepGeometry::findVertexName(const int& id)
{
return getVertexName(findVertex(id));
}
const std::string BrepGeometry::findEdgeName(const int& id)
{
return getEdgeName(findEdge(id));
}
const std::string BrepGeometry::findFaceName(const int& id)
{
return getFaceName(findFace(id));
}
const std::string BrepGeometry::findSolidName(const int& id)
{
return getSolidName(findSolid(id));
}
// -----------------------------
void BrepGeometry::changeVertexName(const int& id, const std::string& name)
throw (XAO_Exception)
{
setVertexName(findVertex(id), name);
}
void BrepGeometry::changeEdgeName(const int& id, const std::string& name)
throw (XAO_Exception)
{
setEdgeName(findEdge(id), name);
}
void BrepGeometry::changeFaceName(const int& id, const std::string& name)
throw (XAO_Exception)
{
setFaceName(findFace(id), name);
}
void BrepGeometry::changeSolidName(const int& id, const std::string& name)
throw (XAO_Exception)
{
setSolidName(findSolid(id), name);
}

View File

@ -0,0 +1,318 @@
// 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_BREPGEOMETRY_HXX__
#define __XAO_BREPGEOMETRY_HXX__
#include <string>
#include <vector>
#include <TopoDS_Shape.hxx>
#include "XAO_XaoUtils.hxx"
#include "XAO_Geometry.hxx"
namespace XAO
{
/**
* @class BrepGeometry
* Representation of a BRep Geometry.
*/
class BrepGeometry : public Geometry
{
public:
/**
* Default Constructor.
*/
BrepGeometry();
/**
* Constructor.
* @param name the name of the geometry.
*/
BrepGeometry(const std::string& name);
virtual ~BrepGeometry() {}
/**
* Gets the format of the geometry.
* @return the format of the geometry.
*/
virtual const XAO::Format getFormat() { return XAO::BREP; }
/**
* Gets the shape as a string.
* @return the shape as a string.
*/
virtual const std::string getShapeString();
/**
* Sets the shape from a string.
* @param shape the shape as a string.
*/
virtual void setShapeString(const std::string& shape);
#ifdef SWIG
%pythoncode %{
def setShape(self, shape):
if shape is not None and 'GetShapeStream' in dir(shape):
self.setShapeString(shape.GetShapeStream())
else:
raise XAO_Exception("Cannot set shape")
%}
#endif
/**
* Gets the shape as a TopoDS_Shape.
* @return the TopoDS_Shape.
*/
TopoDS_Shape getTopoDS_Shape();
/**
* Sets the shape from a TopoDS_Shape.
* @param shape the TopoDS_Shape to set.
*/
void setTopoDS_Shape(const TopoDS_Shape& shape);
/**
* Gives the two extrimities of an edge.
* @param edgeIndex the index of the edge.
* @param vertexA
* @param vertexB
*/
void getEdgeVertices(const int& edgeIndex, int& vertexA, int& vertexB);
/**
* Gets the number of wires of a face (including holes).
* @param faceIndex the index of the face.
* @return the number of wires.
*/
const int countFaceWires(const int& faceIndex);
/**
* Gets the indices of the wires of the face.
* @param faceIndex the index of the face.
* @param wireIndex the index of the wire.
* @return the list of wires for the given face.
*/
std::vector<int> getFaceEdges(const int& faceIndex, const int& wireIndex);
/**
* Gets the number of shells of a solid (including cavities).
* @param solidIndex the index of the solid.
* @return the number of shells.
*/
const int countSolidShells(const int& solidIndex);
/**
* Gets the indices of the shells of the solids.
* @param solidIndex the index of the solid.
* @param shellIndex the index of the shell (for the given solid).
* @return the list of shells for the given solid.
*/
std::vector<int> getSolidFaces(const int& solidIndex, const int& shellIndex);
/**
* Gets the coordinates of a vertex.
* @param vertexIndex the index of the vertex.
* @param xCoord the X coordinate.
* @param yCoord the Y coordinate.
* @param zCoord the Z coordinate.
*/
void getVertexXYZ(const int& vertexIndex, double& xCoord, double& yCoord, double& zCoord)
throw (XAO_Exception);
/**
* Gets the length of an edge.
* @param index the index of the edge.
* @return the length of the edge.
*/
const double getEdgeLength(const int& index);
/**
* Gets the are of a face.
* @param index the index of a face.
* @return the area of the face.
*/
const double getFaceArea(const int& index);
/**
* Gets the volume of a solid.
* @param index the index of the solid.
* @return the volume of the solid.
*/
const double getSolidVolume(const int& index);
/**
* Gets the ID of a vertex.
* @param index the index of the vertex.
* @return the ID of the vertex.
*/
const int getVertexID(const int& index);
/**
* Gets the ID of an edge.
* @param index the index of the edge.
* @return the ID of the edge.
*/
const int getEdgeID(const int& index);
/**
* Gets the ID of a face.
* @param index the index of the face.
* @return the ID of the face.
*/
const int getFaceID(const int& index);
/**
* Gets the ID of a solid.
* @param index the index of the solid.
* @return the ID of the solid.
*/
const int getSolidID(const int& index);
/**
* Sets the ID of a vertex.
* @param index the index of the vertex to set.
* @param id the id to set.
*/
void setVertexID(const int& index, const int& id);
/**
* Sets the ID of an edge.
* @param index the index of the edge to set.
* @param id the id to set.
*/
void setEdgeID(const int& index, const int& id);
/**
* Sets the ID of a face.
* @param index the index of the face to set.
* @param id the id to set.
*/
void setFaceID(const int& index, const int& id);
/**
* Sets the ID of a solid.
* @param index the index of the solid to set.
* @param id the id to set.
*/
void setSolidID(const int& index, const int& id);
/**
* Finds a vertex with its ID.
* @param id the ID of the vertex.
* @return the index of the vertex.
*/
const int findVertex(const int& id);
/**
* Finds an edge with its ID.
* @param id the ID of the edge.
* @return the index of the edge.
*/
const int findEdge(const int& id);
/**
* Finds a face with its ID.
* @param id the ID of the face.
* @return the index of the face.
*/
const int findFace(const int& id);
/**
* Finds a solid with its ID.
* @param id the ID of the solid.
* @return th index of the solid.
*/
const int findSolid(const int& id);
/**
* Finds the name of a vertex with its ID.
* @param id the ID of the vertex.
* @return the name of the vertex.
*/
const std::string findVertexName(const int& id);
/**
* Finds the name of an edge with its ID.
* @param id the ID of the edge.
* @return the name of the edge.
*/
const std::string findEdgeName(const int& id);
/**
* Finds the name of a face with its ID.
* @param id the ID of the face.
* @return the name of the face.
*/
const std::string findFaceName(const int& id);
/**
* Finds the name of a solid with its ID.
* @param id the ID of the solid.
* @return the name of the solid.
*/
const std::string findSolidName(const int& id);
/**
* Changes the name of a vertex.
* @param id the ID of the vertex.
* @param name the name to set.
*/
void changeVertexName(const int& id, const std::string& name) throw (XAO_Exception);
/**
* Changes the name of an edge.
* @param id the ID of the edge
* @param name the name to set.
*/
void changeEdgeName(const int& id, const std::string& name) throw (XAO_Exception);
/**
* Changes the name of a face.
* @param id the ID of the face.
* @param name the name to set.
*/
void changeFaceName(const int& id, const std::string& name) throw (XAO_Exception);
/**
* Changes the name of a solid.
* @param id the ID of the solid.
* @param name the name to set.
*/
void changeSolidName(const int& id, const std::string& name) throw (XAO_Exception);
private:
void initIds();
void initListIds(const TopAbs_ShapeEnum& shapeType, GeometricElementList& eltList);
TopoDS_Shape getSubShape(const TopoDS_Shape& mainShape, const TopAbs_ShapeEnum& shapeType, const int& shapeIndex)
throw (XAO_Exception);
const int countGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType);
std::vector<int> getGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType, const XAO::Dimension& dim);
const int findElement(const XAO::Dimension& dim, const int& id)
throw (XAO_Exception);
private:
TopoDS_Shape m_shape;
};
}
#endif // __XAO_BREPGEOMETRY_HXX__

View File

@ -0,0 +1,60 @@
// 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 "XAO_DoubleField.hxx"
#include "XAO_DoubleStep.hxx"
#include "XAO_XaoUtils.hxx"
using namespace XAO;
DoubleField::DoubleField(const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents, const std::string& name)
: Field(dimension, nbElements, nbComponents, name)
{
}
Step* DoubleField::addNewStep(const int& step)
throw (XAO_Exception)
{
return addStep(step, 0);
}
DoubleStep* DoubleField::addStep(const int& step)
throw (XAO_Exception)
{
return addStep(step, 0);
}
DoubleStep* DoubleField::addStep(const int& step, const int& stamp)
throw (XAO_Exception)
{
if (hasStep(step))
throw XAO_Exception(MsgBuilder() << "Step with number " << step << " already exists.");
DoubleStep* bstep = new DoubleStep(step, stamp, m_nbElements, m_nbComponents);
m_steps.push_back(bstep);
return bstep;
}
DoubleStep* DoubleField::getStep(const int& index)
throw (XAO_Exception)
{
checkStepIndex(index);
return (DoubleStep*)m_steps[index];
}

View File

@ -0,0 +1,76 @@
// 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_DOUBLEFIELD_HXX__
#define __XAO_DOUBLEFIELD_HXX__
#include <string>
#include "XAO_XaoUtils.hxx"
#include "XAO_Field.hxx"
#include "XAO_DoubleStep.hxx"
namespace XAO
{
/**
* @class DoubleField
* Represents a field with double values.
*/
class DoubleField : public Field
{
public:
/**
* Constructor.
* @param dimension the dimension of the field.
* @param nbElements the number of elements.
* @param nbComponents the number of components.
* @param name the name of the field.
*/
DoubleField(const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents, const std::string& name);
virtual const XAO::Type getType() { return XAO::DOUBLE; }
virtual Step* addNewStep(const int& step) throw (XAO_Exception);
/**
* Adds a new step.
* @param step the number of the step.
* @return the newly created step.
*/
DoubleStep* addStep(const int& step) throw (XAO_Exception);
/**
* Adds a new step.
* @param step the number of the step.
* @param stamp the stamp of the step.
* @return the newly created step.
*/
DoubleStep* addStep(const int& step, const int& stamp) throw (XAO_Exception);
/**
* Gets the step of given index.
* @param index the index.
* @return the step for the given index.
*/
DoubleStep* getStep(const int& index) throw (XAO_Exception);
};
}
#endif /* __XAO_DOUBLEFIELD_HXX__ */

148
src/XAO/XAO_DoubleStep.cxx Normal file
View File

@ -0,0 +1,148 @@
// 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 "XAO_DoubleStep.hxx"
#include "XAO_XaoUtils.hxx"
using namespace XAO;
DoubleStep::DoubleStep(const int& step, const int& stamp, const int& nbElements, const int& nbComponents)
{
m_nbElements = nbElements;
m_nbComponents = nbComponents;
m_step = step;
m_stamp = stamp;
m_values.reserve(m_nbElements);
for (int i = 0; i < m_nbElements; ++i)
{
std::vector<double> row;
row.reserve(m_nbComponents);
for (int j = 0; j < m_nbComponents; ++j)
row.push_back(0);
m_values.push_back(row);
}
}
std::vector<double> DoubleStep::getValues()
{
std::vector<double> result;
result.reserve(m_nbElements * m_nbComponents);
std::vector< std::vector<double> >::iterator it;
for (it = m_values.begin(); it != m_values.end(); ++it)
{
std::vector<double> eltValues = *it;
result.insert(result.end(), eltValues.begin(), eltValues.end());
}
return result;
}
std::vector<double> DoubleStep::getElement(const int& element)
throw (XAO_Exception)
{
checkElementIndex(element);
std::vector<double> result(m_values[element]);
return result;
}
std::vector<double> DoubleStep::getComponent(const int& component)
throw (XAO_Exception)
{
checkComponentIndex(component);
std::vector<double> result;
result.reserve(m_nbElements);
std::vector< std::vector<double> >::iterator it;
for (it = m_values.begin(); it != m_values.end(); ++it)
{
std::vector<double> eltValues = *it;
result.push_back(eltValues[component]);
}
return result;
}
const double DoubleStep::getValue(const int& element, const int& component)
throw (XAO_Exception)
{
checkElementIndex(element);
checkComponentIndex(component);
return m_values[element][component];
}
const std::string DoubleStep::getStringValue(const int& element, const int& component)
throw (XAO_Exception)
{
return XaoUtils::doubleToString(getValue(element, component));
}
void DoubleStep::setValues(const std::vector<double>& values)
throw (XAO_Exception)
{
checkNbValues(values.size());
for (int i = 0; i < m_nbElements; ++i)
{
for (int j = 0; j < m_nbComponents; ++j)
{
m_values[i][j] = values[i * m_nbComponents + j];
}
}
}
void DoubleStep::setElement(const int& element, const std::vector<double>& elements)
throw (XAO_Exception)
{
checkElementIndex(element);
checkNbComponents(elements.size());
for (int i = 0; i < m_nbComponents; ++i)
m_values[element][i] = elements[i];
}
void DoubleStep::setComponent(const int& component, const std::vector<double>& components)
throw (XAO_Exception)
{
checkElementIndex(component);
checkNbElements(components.size());
for (int i = 0; i < m_nbElements; ++i)
m_values[i][component] = components[i];
}
void DoubleStep::setValue(const int& element, const int& component, const double& value)
throw (XAO_Exception)
{
checkElementIndex(element);
checkComponentIndex(component);
m_values[element][component] = value;
}
void DoubleStep::setStringValue(const int& element, const int& component, const std::string& value)
throw (XAO_Exception)
{
setValue(element, component, XaoUtils::stringToDouble(value));
}

114
src/XAO/XAO_DoubleStep.hxx Normal file
View File

@ -0,0 +1,114 @@
// 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_DOUBLESTEP_HXX__
#define __XAO_DOUBLESTEP_HXX__
#include <vector>
#include "XAO_XaoUtils.hxx"
#include "XAO_Step.hxx"
namespace XAO
{
/**
* @class DoubleStep
* Step with double values.
*/
class DoubleStep : public Step
{
public:
/**
* Constructor.
* @param step the step number.
* @param stamp the stamp of the step.
* @param nbElements the number elements of the geometry.
* @param nbComponents the number of components of the field.
*/
DoubleStep(const int& step, const int& stamp, const int& nbElements, const int& nbComponents);
virtual const XAO::Type getType() { return XAO::DOUBLE; }
/**
* Gets all the values of the step as a list.
* @return a vector containing all the values of the step.
*/
std::vector<double> getValues();
/**
* Gets all the values for a given element.
* @param element the index of the element.
* @return a vector containing all the values for the given element.
*/
std::vector<double> getElement(const int& element) throw (XAO_Exception);
/**
* Gets all the values for a given component.
* @param component the index of the component.
* @return a vector containing all the values for the given component.
*/
std::vector<double> getComponent(const int& component) throw (XAO_Exception);
/**
* Gets the value for an element and a component.
* @param element the index of the element.
* @param component the index of the component.
* @return the value for the given element and component.
*/
const double getValue(const int& element, const int& component) throw (XAO_Exception);
/**
* Sets all the values from a list.
* @param values the list of values to set.
*/
void setValues(const std::vector<double>& values) throw (XAO_Exception);
/**
* Sets the values for an element.
* @param element the index of the element to set.
* @param elements the values to set.
*/
void setElement(const int& element, const std::vector<double>& elements) throw (XAO_Exception);
/**
* Sets the values for a component.
* @param component the index of the component to set.
* @param components the values to set.
*/
void setComponent(const int& component, const std::vector<double>& components) throw (XAO_Exception);
/**
* Sets the value for an element and a component.
* @param element the index of the element.
* @param component the index of the component.
* @param value the value.
*/
void setValue(const int& element, const int& component, const double& value) throw (XAO_Exception);
virtual const std::string getStringValue(const int& element, const int& component) throw (XAO_Exception);
virtual void setStringValue(const int& element, const int& component, const std::string& value) throw (XAO_Exception);
private:
std::vector< std::vector<double> > m_values;
};
}
#endif /* __XAO_DOUBLESTEP_HXX__ */

67
src/XAO/XAO_Exception.hxx Normal file
View File

@ -0,0 +1,67 @@
// 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_EXCEPTION_HXX__
#define __XAO_EXCEPTION_HXX__
namespace XAO
{
/**
* \class XAO_Exception
* Exception for XAO operations.
*/
class XAO_Exception : public std::exception
{
public:
/**
* Default constructor.
* @param message the exception message.
*/
XAO_Exception(const char* message) : m_message(message)
{
}
virtual ~XAO_Exception() throw() {};
/**
* Returns the error message.
* @return the error message.
*/
virtual const char* what() const throw ()
{
return m_message;
}
#ifdef SWIG
%extend
{
std::string __str__() const
{
return std::string(self->what());
}
}
#endif
private:
const char* m_message;
};
}
#endif /* __XAO_EXCEPTION_HXX__ */

138
src/XAO/XAO_Field.cxx Normal file
View File

@ -0,0 +1,138 @@
// 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 <string>
#include <iostream>
#include "XAO_Xao.hxx"
#include "XAO_Field.hxx"
#include "XAO_BooleanField.hxx"
#include "XAO_IntegerField.hxx"
#include "XAO_DoubleField.hxx"
#include "XAO_StringField.hxx"
#include "XAO_XaoUtils.hxx"
using namespace XAO;
// -------------------------------------------------------
Field::Field(const XAO::Dimension& dimension,
const int& nbElements, const int& nbComponents, const std::string& name)
: m_name(name), m_dimension(dimension), m_nbElements(nbElements), m_nbComponents(nbComponents)
{
m_components.reserve(nbComponents);
for (int i = 0; i < nbComponents; ++i)
m_components.push_back("");
}
Field::~Field()
{
for (int i = 0; i < m_steps.size(); ++i)
delete m_steps[i];
}
Field* Field::createField(const XAO::Type& type, const XAO::Dimension& dimension,
const int& nbElements, const int& nbComponents, const std::string& name)
throw (XAO_Exception)
{
if (type == XAO::BOOLEAN)
return new BooleanField(dimension, nbElements, nbComponents, name);
if (type == XAO::INTEGER)
return new IntegerField(dimension, nbElements, nbComponents, name);
if (type == XAO::DOUBLE)
return new DoubleField(dimension, nbElements, nbComponents, name);
if (type == XAO::STRING)
return new StringField(dimension, nbElements, nbComponents, name);
throw XAO_Exception(MsgBuilder() << "Bad Type: " << type);
}
const std::string Field::getComponentName(const int& index)
throw (XAO_Exception)
{
checkComponent(index);
return m_components[index];
}
void Field::setComponentName(const int& index, const std::string& name)
throw (XAO_Exception)
{
checkComponent(index);
m_components[index] = name;
}
void Field::setComponentsNames(const std::vector<std::string>& names)
throw (XAO_Exception)
{
for (int i = 0; i < names.size(); ++i)
{
if (i < m_nbComponents)
m_components[i] = names[i];
}
}
bool Field::removeStep(Step* step)
{
std::vector<Step*>::iterator it = m_steps.begin();
for (; it != m_steps.end(); ++it)
{
Step* current = *it;
if (step == current)
{
m_steps.erase(it);
return true;
}
}
return false;
}
bool Field::hasStep(const int& step)
{
std::vector<Step*>::iterator it = m_steps.begin();
for (; it != m_steps.end(); ++it)
{
Step* current = *it;
if (current->getStep() == step)
return true;
}
return false;
}
void Field::checkComponent(const int& component)
throw (XAO_Exception)
{
if (component < m_nbComponents && component >= 0)
return;
throw XAO_Exception(MsgBuilder() << "Step index is out of range [0, "
<< m_nbComponents-1 << "]: " << component);
}
void Field::checkStepIndex(const int& step)
throw (XAO_Exception)
{
if (step < m_steps.size() && step >= 0)
return;
throw XAO_Exception(MsgBuilder() << "Step index is out of range [0, "
<< m_steps.size()-1 << "]: " << step);
}

213
src/XAO/XAO_Field.hxx Normal file
View File

@ -0,0 +1,213 @@
// 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_FIELD_HXX__
#define __XAO_FIELD_HXX__
#include <string>
#include <vector>
#include "XAO_XaoUtils.hxx"
#include "XAO_Step.hxx"
namespace XAO
{
typedef std::vector<Step*>::iterator stepIterator;
/**
* @class Field
* A geometrical Field.
*/
class Field
{
protected:
/**
* Constructor.
* @param dimension the dimension ot the field.
* @param nbElements the number of elements.
* @param nbComponents the number of components.
* @param name the name of the field.
*/
Field(const XAO::Dimension& dimension,
const int& nbElements, const int& nbComponents, const std::string& name);
public:
/**
/**
* Creates a Field of the given type.
* @param type the type of the field to create.
* @param dimension the dimension.
* @param nbElements the number of geometrical elements.
* @param nbComponents the number of components.
* @name the name of the field.
* @return the created field.
*/
static Field* createField(const XAO::Type& type, const XAO::Dimension& dimension,
const int& nbElements, const int& nbComponents,
const std::string& name = std::string(""))
throw (XAO_Exception);
/**
* Destructor.
*/
virtual ~Field();
/**
* Gets the Type of the field.
* @return the Type of the field.
*/
virtual const XAO::Type getType() = 0;
/**
* Gets the name of the Field.
* @return the name of the Field.
*/
const std::string getName() const
{
return m_name;
}
/**
* Sets the name of the Field.
* @param name the name to set.
*/
void setName(const std::string& name)
{
m_name = name;
}
/**
* Gets the Dimension of the Field.
* @return the Dimension of the Field.
*/
const XAO::Dimension getDimension() const
{
return m_dimension;
}
/**
* Gets the number of elements of each step.
* @return the number of elements of each step.
*/
const int countElements() const
{
return m_nbElements;
}
/**
* Gets the number of components.
* @return the number of components.
*/
const int countComponents() const
{
return m_nbComponents;
}
/**
* Gets the number of values for each step.
* @return the number of values for each step.
*/
const int countValues() const
{
return m_nbElements * m_nbComponents;
}
/**
* Gets the number of the steps.
* @return the number of steps.
*/
const int countSteps() const { return m_steps.size(); }
/**
* Gets the name of a component.
* @param index the index of the component to get.
* @return the name of the component for the given index.
*/
const std::string getComponentName(const int& index) throw (XAO_Exception);
/**
* Sets the name of a component.
* @param componentIndex the index of the component to set.
* @param name the name to set.
*/
void setComponentName(const int& componentIndex, const std::string& name) throw (XAO_Exception);
/**
* Sets the name of the components.
* @param names the names to set.
*/
void setComponentsNames(const std::vector<std::string>& names) throw (XAO_Exception);
/**
* Adds a new step of the same type than the field.
* @param number the numer of the step.
* @return the new create step.
*/
virtual Step* addNewStep(const int& number) throw (XAO_Exception) = 0;
/**
* Remove a step.
* @param step the step to remove.
* @return true if the step has been removed, false otherwise.
*/
bool removeStep(Step* step);
/**
* Verifies if the field has a step with the given step number.
* @param step the step number.
* @return true if the field has a step for the given number.
*/
bool hasStep(const int& step);
/**
* Returns the first step.
* @return an iterator on the first step.
*/
stepIterator begin() { return m_steps.begin(); }
/**
* Returns the last step.
* @return an iterator on the last step.
*/
stepIterator end() { return m_steps.end(); }
protected:
void checkComponent(const int& component) throw (XAO_Exception);
void checkStepIndex(const int& step) throw (XAO_Exception);
protected:
/** The name of the Field. */
std::string m_name;
/** The dimension of the Field. */
XAO::Dimension m_dimension;
/** The number of components. */
int m_nbComponents;
/** The components of the field. */
std::vector<std::string> m_components;
/** The number of elements. */
int m_nbElements;
/** The list of steps. */
std::vector<Step*> m_steps;
};
}
#endif

View File

@ -0,0 +1,131 @@
// 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 "XAO_GeometricElement.hxx"
#include "XAO_XaoUtils.hxx"
using namespace XAO;
GeometricElement::GeometricElement()
{
m_name = "";
m_reference = "";
}
GeometricElement::GeometricElement(const std::string& name, const std::string& reference)
{
m_name = name;
m_reference = reference;
}
GeometricElement::~GeometricElement()
{
}
const bool GeometricElement::hasName()
{
return !m_name.empty();
}
GeometricElementList::GeometricElementList()
{
setSize(0);
}
GeometricElementList::GeometricElementList(const int& count)
{
setSize(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::checkElementIndex(const int& index) const
throw (XAO_Exception)
{
if (m_count >= 0 && index < m_count)
return;
throw XAO_Exception(MsgBuilder() << "Index of element is out of range [0, "
<< m_count-1 << "]: " << index);
}
void GeometricElementList::setElement(const int& index, const std::string& name, const std::string& reference)
throw (XAO_Exception)
{
checkElementIndex(index);
m_elements[index].setName(name);
m_elements[index].setReference(reference);
}
const std::string GeometricElementList::getName(const int& index)
throw (XAO_Exception)
{
checkElementIndex(index);
return m_elements[index].getName();
}
void GeometricElementList::setName(const int& index, const std::string& name)
throw (XAO_Exception)
{
checkElementIndex(index);
m_elements[index].setName(name);
}
const bool GeometricElementList::hasName(const int& index)
throw (XAO_Exception)
{
checkElementIndex(index);
return m_elements[index].hasName();
}
const std::string GeometricElementList::getReference(const int& index)
throw (XAO_Exception)
{
checkElementIndex(index);
return m_elements[index].getReference();
}
void GeometricElementList::setReference(const int& index, const std::string& name)
throw (XAO_Exception)
{
checkElementIndex(index);
m_elements[index].setReference(name);
}
const int GeometricElementList::getIndexByReference(const std::string& ref)
throw (XAO_Exception)
{
for (int index = 0; index < m_count; ++index)
{
if (ref == m_elements[index].getReference())
return index;
}
throw XAO_Exception(MsgBuilder() << "Reference not found: " << ref);
}

View File

@ -0,0 +1,213 @@
// 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>
#include "XAO_Exception.hxx"
namespace XAO
{
/**
* \class GeometricElement
* Generic class to manipulate a topologic element (vertex, edge, face or solid).
*/
class GeometricElement
{
public:
/**
* Default constructor.
*/
GeometricElement();
/**
* Constructor with name and reference.
* \param name the name of the element.
* \param reference the reference of the element.
*/
GeometricElement(const std::string& name, const std::string& reference);
/**
* Destructor.
*/
virtual ~GeometricElement();
/**
* Gets the name of the element.
* \return the name.
*/
const std::string getName()
{
return m_name;
}
/**
* Sets the name of the element
* \param name the name to set.
*/
void setName(const std::string& name)
{
m_name = name;
}
/**
* Checks if the element has a name.
* @return true if the element has a name, false otherwise.
*/
const bool hasName();
/**
* Gets the reference of the element.
* \return the reference.
*/
const std::string getReference()
{
return m_reference;
}
/**
* Sets the reference of the element.
* \param reference the reference to set.
*/
void setReference(const std::string& reference)
{
m_reference = reference;
}
private:
/** The name of the element. */
std::string m_name;
/** The reference of the element. */
std::string m_reference;
};
/**
* \class GeometricElementList
* Generic class to manipulate a list of topologic element.
*/
class GeometricElementList
{
public:
/**
* Default constructor.
*/
GeometricElementList();
/**
* Constructor with size.
* \param nb the size to set.
*/
GeometricElementList(const int& nb);
/**
* Destructor.
*/
virtual ~GeometricElementList() {}
/**
* Gets the size of the list.
* \return the size of the list.
*/
const int getSize() const { return m_count; }
/**
* Sets the size of the list.
* \param nb the size to set.
* \warning the list will be cleared.
*/
void setSize(const int& nb);
/**
* Sets the name and the reference of an element.
* \param index the index of the element to set.
* \param name the name to set.
* \param reference the reference to set.
* \throw XAO_Exception if index is bigger than the size of the list.
*/
void setElement(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception);
/**
* Gets the name of an element.
* \param index the index of the element to set.
* \return the name of the element with the given index.
* \throw XAO_Exception if index is bigger than the size of the list.
*/
const std::string getName(const int& index) throw (XAO_Exception);
/**
* Sets the name of an element.
* \param index the index of the element.
* \param name the name to set.
* \throw XAO_Exception if index is bigger than the size of the list.
*/
void setName(const int& index, const std::string& name) throw (XAO_Exception);
/**
* Checks if an element has a name.
* @param index the index of the element.
* @return true if the element has a name, false otherwise.
*/
const bool hasName(const int& index) throw (XAO_Exception);
/**
* Gets the reference of an element.
* \param index the index of the element.
* \return the reference of the element.
* \throw XAO_Exception if index is bigger than the size of the list.
*/
const std::string getReference(const int& index) throw (XAO_Exception);
/**
* Sets the reference of an element.
* \param index the index of the element to set.
* \param reference the reference to set.
* \throw XAO_Exception if index is bigger than the size of the list.
*/
void setReference(const int& index, const std::string& reference) throw (XAO_Exception);
/**
* Gets the index of an element using its reference.
* \param reference the searched reference.
* \return the index of the element or -1 if no element found.
*/
const int getIndexByReference(const std::string& reference) throw (XAO_Exception);
/**
* Iterator on the element of the list.
*/
typedef std::map<int, GeometricElement>::iterator iterator;
/**
* Gets an iterator on the first element.
* @return an iterator on the first element.
*/
iterator begin() { return m_elements.begin(); }
/**
* Gets an iterator on the last element.
* @return an iterator on the last element.
*/
iterator end() { return m_elements.end(); }
private:
void checkElementIndex(const int& index) const throw (XAO_Exception);
private:
int m_count;
std::map<int, GeometricElement> m_elements;
};
}
#endif /* __XAO_GEOMETRICELEMENT_HXX__ */

195
src/XAO/XAO_Geometry.cxx Normal file
View File

@ -0,0 +1,195 @@
// 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 : Nathalie Gore (OpenCascade)
#include "XAO_XaoUtils.hxx"
#include "XAO_Geometry.hxx"
#include "XAO_BrepGeometry.hxx"
using namespace XAO;
Geometry::Geometry(const std::string& name)
: m_name(name)
{
m_readOnly = false;
}
Geometry* Geometry::createGeometry(const XAO::Format& format)
throw (XAO_Exception)
{
return createGeometry(format, "");
}
Geometry* Geometry::createGeometry(const XAO::Format& format, const std::string& name)
throw (XAO_Exception)
{
if (format == XAO::BREP)
return new BrepGeometry(name);
throw XAO_Exception(MsgBuilder() << "Geometry format not supported: " << format);
}
Geometry::~Geometry()
{
}
void Geometry::checkReadOnly()
throw (XAO_Exception)
{
if (m_readOnly)
throw XAO_Exception("Geometry is read only.");
}
const int Geometry::countElements(const XAO::Dimension& dim) const
throw (XAO_Exception)
{
if (dim == XAO::VERTEX)
return countVertices();
if (dim == XAO::EDGE)
return countEdges();
if (dim == XAO::FACE)
return countFaces();
if (dim == XAO::SOLID)
return countSolids();
throw XAO_Exception(MsgBuilder() << "Unknown dimension:" << dim);
}
const std::string Geometry::getElementReference(const XAO::Dimension& dim, const int& index)
throw (XAO_Exception)
{
if (dim == XAO::VERTEX)
return getVertexReference(index);
if (dim == XAO::EDGE)
return getEdgeReference(index);
if (dim == XAO::FACE)
return getFaceReference(index);
if (dim == XAO::SOLID)
return getSolidReference(index);
throw XAO_Exception(MsgBuilder() << "Unknown dimension:" << dim);
}
const int Geometry::getElementIndexByReference(const XAO::Dimension& dim, const std::string& reference)
throw (XAO_Exception)
{
if (dim == XAO::VERTEX)
return getVertexIndexByReference(reference);
if (dim == XAO::EDGE)
return getEdgeIndexByReference(reference);
if (dim == XAO::FACE)
return getFaceIndexByReference(reference);
if (dim == XAO::SOLID)
return getSolidIndexByReference(reference);
throw XAO_Exception(MsgBuilder() << "Unknown dimension:" << dim);
}
GeometricElementList::iterator Geometry::begin(const XAO::Dimension& dim)
throw (XAO_Exception)
{
if (dim == XAO::VERTEX)
return m_vertices.begin();
if (dim == XAO::EDGE)
return m_edges.begin();
if (dim == XAO::FACE)
return m_faces.begin();
if (dim == XAO::SOLID)
return m_solids.begin();
throw XAO_Exception(MsgBuilder() << "Unknown dimension:" << dim);
}
GeometricElementList::iterator Geometry::end(const XAO::Dimension& dim)
throw (XAO_Exception)
{
if (dim == XAO::VERTEX)
return m_vertices.end();
if (dim == XAO::EDGE)
return m_edges.end();
if (dim == XAO::FACE)
return m_faces.end();
if (dim == XAO::SOLID)
return m_solids.end();
throw XAO_Exception(MsgBuilder() << "Unknown dimension:" << dim);
}
void Geometry::setCountVertices(const int& nb) throw (XAO_Exception)
{
checkReadOnly();
m_vertices.setSize(nb);
}
void Geometry::setCountEdges(const int& nb) throw (XAO_Exception)
{
checkReadOnly();
m_edges.setSize(nb);
}
void Geometry::setCountFaces(const int& nb) throw (XAO_Exception)
{
checkReadOnly();
m_faces.setSize(nb);
}
void Geometry::setCountSolids(const int& nb) throw (XAO_Exception)
{
checkReadOnly();
m_solids.setSize(nb);
}
void Geometry::setVertexReference(const int& index, const std::string& reference) throw (XAO_Exception)
{
checkReadOnly();
m_vertices.setReference(index, reference);
}
void Geometry::setEdgeReference(const int& index, const std::string& reference) throw (XAO_Exception)
{
checkReadOnly();
m_edges.setReference(index, reference);
}
void Geometry::setFaceReference(const int& index, const std::string& reference) throw (XAO_Exception)
{
checkReadOnly();
m_faces.setReference(index, reference);
}
void Geometry::setSolidReference(const int& index, const std::string& reference) throw (XAO_Exception)
{
checkReadOnly();
m_solids.setReference(index, reference);
}
void Geometry::setVertex(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception)
{
checkReadOnly();
m_vertices.setElement(index, name, reference);
}
void Geometry::setEdge(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception)
{
checkReadOnly();
m_edges.setElement(index, name, reference);
}
void Geometry::setFace(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception)
{
checkReadOnly();
m_faces.setElement(index, name, reference);
}
void Geometry::setSolid(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception)
{
checkReadOnly();
m_solids.setElement(index, name, reference);
}

168
src/XAO/XAO_Geometry.hxx Normal file
View File

@ -0,0 +1,168 @@
// Copyright (C) 2007-2012 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 : Nathalie Gore (OpenCascade)
#ifndef __XAO_GEOMETRY_HXX__
#define __XAO_GEOMETRY_HXX__
#include <string>
#include "XAO_XaoUtils.hxx"
#include "XAO_Exception.hxx"
#include "XAO_GeometricElement.hxx"
namespace XAO
{
/**
* @class Geometry
* Base class for geometries.
*/
class Geometry
{
protected:
/**
* Constructor.
* @param name the name of the Geometry.
*/
Geometry(const std::string& name);
public:
/**
* Creates a geometry.
* @param format the format of the geometry.
* @return the created geometry.
*/
static Geometry* createGeometry(const XAO::Format& format) throw (XAO_Exception);
/**
* Constructor.
* Creates a geometry.
* @name name the name of the geometry.
* @return the created geometry.
*/
static Geometry* createGeometry(const XAO::Format& format, const std::string& name)
throw (XAO_Exception);
/** Destructor. */
virtual ~Geometry();
/**
* Gets the name of the geometry.
* @return the name of the geometry.
*/
const std::string getName()
{
return m_name;
}
/**
* Sets the name of the geometry.
* @param name the name to set.
*/
void setName(const std::string& name)
{
m_name = name;
}
/**
* Gets the format of the geometry.
* @return the format of the geometry.
*/
virtual const XAO::Format getFormat() = 0;
virtual const std::string getShapeString() = 0;
virtual void setShapeString(const std::string& shape) = 0;
const int countElements(const XAO::Dimension& dim) const throw (XAO_Exception);
const int countVertices() const { return m_vertices.getSize(); }
const int countEdges() const { return m_edges.getSize(); }
const int countFaces() const { return m_faces.getSize(); }
const int countSolids() const { return m_solids.getSize(); }
void setCountVertices(const int& nb) throw (XAO_Exception);
void setCountEdges(const int& nb) throw (XAO_Exception);
void setCountFaces(const int& nb) throw (XAO_Exception);
void setCountSolids(const int& nb) throw (XAO_Exception);
const std::string getVertexName(const int& index) throw (XAO_Exception) { return m_vertices.getName(index); }
const std::string getEdgeName(const int& index) throw (XAO_Exception) { return m_edges.getName(index); }
const std::string getFaceName(const int& index) throw (XAO_Exception) { return m_faces.getName(index); }
const std::string getSolidName(const int& index) throw (XAO_Exception) { return m_solids.getName(index); }
void setVertexName(const int& index, const std::string& name) throw (XAO_Exception) { m_vertices.setName(index, name); }
void setEdgeName(const int& index, const std::string& name) throw (XAO_Exception) { m_edges.setName(index, name); }
void setFaceName(const int& index, const std::string& name) throw (XAO_Exception) { m_faces.setName(index, name); }
void setSolidName(const int& index, const std::string& name) throw (XAO_Exception) { m_solids.setName(index, name); }
const bool hasVertexName(const int& index) throw (XAO_Exception) { return m_vertices.hasName(index); }
const bool hasEdgeName(const int& index) throw (XAO_Exception) { return m_edges.hasName(index); }
const bool hasFaceName(const int& index) throw (XAO_Exception) { return m_faces.hasName(index); }
const bool hasSolidName(const int& index) throw (XAO_Exception) { return m_solids.hasName(index); }
const std::string getVertexReference(const int& index) throw (XAO_Exception) { return m_vertices.getReference(index); }
const std::string getEdgeReference(const int& index) throw (XAO_Exception) { return m_edges.getReference(index); }
const std::string getFaceReference(const int& index) throw (XAO_Exception) { return m_faces.getReference(index); }
const std::string getSolidReference(const int& index) throw (XAO_Exception) { return m_solids.getReference(index); }
const std::string getElementReference(const XAO::Dimension& dim, const int& index) throw (XAO_Exception);
void setVertexReference(const int& index, const std::string& reference) throw (XAO_Exception);
void setEdgeReference(const int& index, const std::string& reference) throw (XAO_Exception);
void setFaceReference(const int& index, const std::string& reference) throw (XAO_Exception);
void setSolidReference(const int& index, const std::string& reference) throw (XAO_Exception);
void setVertex(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception);
void setEdge(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception);
void setFace(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception);
void setSolid(const int& index, const std::string& name, const std::string& reference) throw (XAO_Exception);
const int getVertexIndexByReference(const std::string& reference) { return m_vertices.getIndexByReference(reference); }
const int getEdgeIndexByReference(const std::string& reference) { return m_edges.getIndexByReference(reference); }
const int getFaceIndexByReference(const std::string& reference) { return m_faces.getIndexByReference(reference); }
const int getSolidIndexByReference(const std::string& reference) { return m_solids.getIndexByReference(reference); }
const int getElementIndexByReference(const XAO::Dimension& dim, const std::string& reference) throw (XAO_Exception);
GeometricElementList::iterator begin(const XAO::Dimension& dim) throw (XAO_Exception);
GeometricElementList::iterator end(const XAO::Dimension& dim) throw (XAO_Exception);
/**
* Verifies if the geometry is read only.
* @return true if the geometry is read only.
*/
bool isReadOnly() { return m_readOnly; }
/**
* Sets the geometry read only.
*/
void setReadOnly() { m_readOnly = true; }
protected:
void checkReadOnly() throw (XAO_Exception);
protected:
std::string m_name;
GeometricElementList m_vertices;
GeometricElementList m_edges;
GeometricElementList m_faces;
GeometricElementList m_solids;
bool m_readOnly;
};
}
#endif

61
src/XAO/XAO_Group.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 : Nathalie Gore (OpenCascade), Frederic Pons (OpenCascade)
#include "XAO_XaoUtils.hxx"
#include "XAO_Group.hxx"
using namespace XAO;
Group::Group(const XAO::Dimension& dim, const int& nbElements, const std::string& name)
throw (XAO_Exception)
{
if (dim == XAO::WHOLE)
throw XAO_Exception("Dimension WHOLE is not valid for group.");
m_name = name;
m_dimension = dim;
m_count = 0;
m_nbElements = nbElements;
}
Group::~Group()
{
}
void Group::checkIndex(const int& element)
throw (XAO_Exception)
{
if (element < m_elements.size() && element >= 0)
return;
throw XAO_Exception(MsgBuilder() << "Index of element is out of range [0, "
<< m_elements.size()-1 << "]: " << element);
}
void Group::add(const int& value)
{
m_elements.insert(value);
}
void Group::remove(const int& value)
{
m_elements.erase(value);
}

157
src/XAO/XAO_Group.hxx Normal file
View File

@ -0,0 +1,157 @@
// 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 : Nathalie Gore (OpenCascade), Frederic Pons (OpenCascade)
#ifndef __XAO_GROUP_HXX__
#define __XAO_GROUP_HXX__
#include <string>
#include <set>
#include "XAO_XaoUtils.hxx"
namespace XAO
{
/**
* \class Group
* Class to represent a Geometrical Group.
*/
class Group
{
public:
/**
* Constructor.
* @param dim the dimension of the group.
* @param nbElements the number of geometrical elements for the dimension in the geometry.
* @param name the name of the group.
*/
Group(const XAO::Dimension& dim, const int& nbElements, const std::string& name = std::string(""))
throw (XAO_Exception);
/**
* Destructor.
*/
virtual ~Group();
/**
* Gets the name of the group.
* \return the name of the group.
*/
const std::string getName()
{
return m_name;
}
/**
* Sets the name of the group.
* \param name the name to set.
*/
void setName(const std::string& name)
{
m_name = name;
}
/**
* Gets the dimension of the group.
* \return the dimension of the group.
*/
const XAO::Dimension getDimension()
{
return m_dimension;
}
/**
* Gets the numbers of elements in the geometry of the same type than the group.
* \return the number of elements in the associated geometry.
*/
const int getNbElements()
{
return m_nbElements;
}
/**
* Gets the number of elements in the group.
* \return the number of elements.
*/
const int count() const
{
return m_elements.size();
}
/**
* Gets the reference of an element.
* \param index the index of the element.
* \return the reference of the element.
* \note use begin() and end() if you need to iterate.
*/
const int get(const int& index)
{
checkIndex(index);
std::set<int>::iterator it = m_elements.begin();
std::advance(it, index);
return (*it);
}
/**
* Adds an element to the group.
* \param value the index of the element to add.
*/
void add(const int& value);
/**
* Removes an element from the group.
* \param value the index of the element to remove.
*/
void remove(const int& value);
/**
* Gets an iterator on the first element in the group.
* @return an iterator on the first element.
*/
std::set<int>::iterator begin() { return m_elements.begin(); }
/**
* Gets an iterator on the last element in the group.
* @return an iterator on the last element.
*/
std::set<int>::iterator end() { return m_elements.end(); }
private:
/**
* Ensures that the given element is valid.
* @param element
* @throw XAO_Exception if element is bigger than the number of elements.
*/
void checkIndex(const int& element)
throw (XAO_Exception);
private:
/** The name of the group. */
std::string m_name;
/** The number of elements in the associated geometry. */
int m_nbElements;
/** The dimension of the group. */
XAO::Dimension m_dimension;
/** The number of elements in the group. */
int m_count;
/** The elements of the group. */
std::set<int> m_elements;
};
}
#endif

View File

@ -0,0 +1,60 @@
// 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 "XAO_IntegerField.hxx"
#include "XAO_IntegerStep.hxx"
#include "XAO_XaoUtils.hxx"
using namespace XAO;
IntegerField::IntegerField(const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents, const std::string& name)
: Field(dimension, nbElements, nbComponents, name)
{
}
Step* IntegerField::addNewStep(const int& step)
throw (XAO_Exception)
{
return addStep(step, 0);
}
IntegerStep* IntegerField::addStep(const int& step)
throw (XAO_Exception)
{
return addStep(step, 0);
}
IntegerStep* IntegerField::addStep(const int& step, const int& stamp)
throw (XAO_Exception)
{
if (hasStep(step))
throw XAO_Exception(MsgBuilder() << "Step with number " << step << " already exists.");
IntegerStep* bstep = new IntegerStep(step, stamp, m_nbElements, m_nbComponents);
m_steps.push_back(bstep);
return bstep;
}
IntegerStep* IntegerField::getStep(const int& index)
throw (XAO_Exception)
{
checkStepIndex(index);
return (IntegerStep*)m_steps[index];
}

View File

@ -0,0 +1,76 @@
// 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_INTEGERFIELD_HXX__
#define __XAO_INTEGERFIELD_HXX__
#include <string>
#include "XAO_XaoUtils.hxx"
#include "XAO_Field.hxx"
#include "XAO_IntegerStep.hxx"
namespace XAO
{
/**
* @class IntegerField
* Represents a field with integer values.
*/
class IntegerField : public Field
{
public:
/**
* Constructor.
* @param dimension the dimension of the field.
* @param nbElements the number of elements.
* @param nbComponents the number of components.
* @param name the name of the field.
*/
IntegerField(const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents, const std::string& name);
virtual const XAO::Type getType() { return XAO::INTEGER; }
virtual Step* addNewStep(const int& step) throw (XAO_Exception);
/**
* Adds a new step.
* @param step the number of the step.
* @return the newly created step.
*/
IntegerStep* addStep(const int& step) throw (XAO_Exception);
/**
* Adds a new step.
* @param step the number of the step.
* @param stamp the stamp of the step.
* @return the newly created step.
*/
IntegerStep* addStep(const int& step, const int& stamp) throw (XAO_Exception);
/**
* Gets the step of given index.
* @param index the index of the step.
* @return the step for the given index.
*/
IntegerStep* getStep(const int& index) throw (XAO_Exception);
};
}
#endif /* __XAO_INTEGERFIELD_HXX__ */

148
src/XAO/XAO_IntegerStep.cxx Normal file
View File

@ -0,0 +1,148 @@
// 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 "XAO_IntegerStep.hxx"
#include "XAO_XaoUtils.hxx"
using namespace XAO;
IntegerStep::IntegerStep(const int& step, const int& stamp, const int& nbElements, const int& nbComponents)
{
m_nbElements = nbElements;
m_nbComponents = nbComponents;
m_step = step;
m_stamp = stamp;
m_values.reserve(m_nbElements);
for (int i = 0; i < m_nbElements; ++i)
{
std::vector<int> row;
row.reserve(m_nbComponents);
for (int j = 0; j < m_nbComponents; ++j)
row.push_back(0);
m_values.push_back(row);
}
}
std::vector<int> IntegerStep::getValues()
{
std::vector<int> result;
result.reserve(m_nbElements * m_nbComponents);
std::vector< std::vector<int> >::iterator it;
for (it = m_values.begin(); it != m_values.end(); ++it)
{
std::vector<int> eltValues = *it;
result.insert(result.end(), eltValues.begin(), eltValues.end());
}
return result;
}
std::vector<int> IntegerStep::getElement(const int& element)
throw (XAO_Exception)
{
checkElementIndex(element);
std::vector<int> result(m_values[element]);
return result;
}
std::vector<int> IntegerStep::getComponent(const int& component)
throw (XAO_Exception)
{
checkComponentIndex(component);
std::vector<int> result;
result.reserve(m_nbElements);
std::vector< std::vector<int> >::iterator it;
for (it = m_values.begin(); it != m_values.end(); ++it)
{
std::vector<int> eltValues = *it;
result.push_back(eltValues[component]);
}
return result;
}
const int IntegerStep::getValue(const int& element, const int& component)
throw (XAO_Exception)
{
checkElementIndex(element);
checkComponentIndex(component);
return m_values[element][component];
}
const std::string IntegerStep::getStringValue(const int& element, const int& component)
throw (XAO_Exception)
{
return XaoUtils::intToString(getValue(element, component));
}
void IntegerStep::setValues(const std::vector<int>& values)
throw (XAO_Exception)
{
checkNbValues(values.size());
for (int i = 0; i < m_nbElements; ++i)
{
for (int j = 0; j < m_nbComponents; ++j)
{
m_values[i][j] = values[i * m_nbComponents + j];
}
}
}
void IntegerStep::setElement(const int& element, const std::vector<int>& elements)
throw (XAO_Exception)
{
checkElementIndex(element);
checkNbComponents(elements.size());
for (int i = 0; i < m_nbComponents; ++i)
m_values[element][i] = elements[i];
}
void IntegerStep::setComponent(const int& component, const std::vector<int>& components)
throw (XAO_Exception)
{
checkElementIndex(component);
checkNbElements(components.size());
for (int i = 0; i < m_nbElements; ++i)
m_values[i][component] = components[i];
}
void IntegerStep::setValue(const int& element, const int& component, const int& value)
throw (XAO_Exception)
{
checkElementIndex(element);
checkComponentIndex(component);
m_values[element][component] = value;
}
void IntegerStep::setStringValue(const int& element, const int& component, const std::string& value)
throw (XAO_Exception)
{
setValue(element, component, XaoUtils::stringToInt(value));
}

114
src/XAO/XAO_IntegerStep.hxx Normal file
View File

@ -0,0 +1,114 @@
// 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_INTEGERSTEP_HXX__
#define __XAO_INTEGERSTEP_HXX__
#include <vector>
#include "XAO_XaoUtils.hxx"
#include "XAO_Step.hxx"
namespace XAO
{
/**
* @class IntegerStep
* Step with integer values.
*/
class IntegerStep : public Step
{
public:
/**
* Constructor.
* @param step the step number.
* @param stamp the stamp of the step.
* @param nbElements the number elements of the geometry.
* @param nbComponents the number of components of the field.
*/
IntegerStep(const int& step, const int& stamp, const int& nbElements, const int& nbComponents);
virtual const XAO::Type getType() { return XAO::INTEGER; }
/**
* Gets all the values of the step as a list.
* @return a vector containing all the values of the step.
*/
std::vector<int> getValues();
/**
* Gets all the values for a given element.
* @param element the index of the element.
* @return a vector containing all the values for the given element.
*/
std::vector<int> getElement(const int& element) throw (XAO_Exception);
/**
* Gets all the values for a given component.
* @param component the index of the component.
* @return a vector containing all the values for the given component.
*/
std::vector<int> getComponent(const int& component) throw (XAO_Exception);
/**
* Gets the value for an element and a component.
* @param element the index of the element.
* @param component the index of the component.
* @return the value for the given element and component.
*/
const int getValue(const int& element, const int& component) throw (XAO_Exception);
/**
* Sets all the values from a list.
* @param values the list of values to set.
*/
void setValues(const std::vector<int>& values) throw (XAO_Exception);
/**
* Sets the values for an element.
* @param element the index of the element to set.
* @param elements the values to set.
*/
void setElement(const int& element, const std::vector<int>& elements) throw (XAO_Exception);
/**
* Sets the values for a component.
* @param component the index of the component to set.
* @param components the values to set.
*/
void setComponent(const int& component, const std::vector<int>& components) throw (XAO_Exception);
/**
* Sets the value for an element and a component.
* @param element the index of the element.
* @param component the index of the component.
* @param value the value.
*/
void setValue(const int& element, const int& component, const int& value) throw (XAO_Exception);
virtual const std::string getStringValue(const int& element, const int& component) throw (XAO_Exception);
virtual void setStringValue(const int& element, const int& component, const std::string& value) throw (XAO_Exception);
private:
std::vector< std::vector<int> > m_values;
};
}
#endif /* __XAO_INTEGERSTEP_HXX__ */

79
src/XAO/XAO_Step.cxx Normal file
View File

@ -0,0 +1,79 @@
// 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 "XAO_Xao.hxx"
#include "XAO_XaoUtils.hxx"
#include "XAO_Step.hxx"
#include "XAO_BooleanStep.hxx"
#include "XAO_IntegerStep.hxx"
#include "XAO_DoubleStep.hxx"
#include "XAO_StringStep.hxx"
using namespace XAO;
void Step::checkElementIndex(const int& element)
throw (XAO_Exception)
{
if (element < m_nbElements && element >= 0)
return;
throw XAO_Exception(MsgBuilder() << "Element index is out of range [0, "
<< m_nbElements-1 << "]: " << element);
}
void Step::checkComponentIndex(const int& component)
throw (XAO_Exception)
{
if (component < m_nbComponents && component >= 0)
return;
throw XAO_Exception(MsgBuilder() << "Component index is out of range [0, "
<< m_nbComponents-1 << "]: " << component);
}
void Step::checkNbElements(const int& nbElements)
throw (XAO_Exception)
{
if (nbElements == m_nbElements)
return;
throw XAO_Exception(MsgBuilder() << "Invalid number of elements: " << nbElements
<< ", expected " << m_nbElements);
}
void Step::checkNbComponents(const int& nbComponents)
throw (XAO_Exception)
{
if (nbComponents == m_nbComponents)
return;
throw XAO_Exception(MsgBuilder() << "Invalid number of components: " << nbComponents
<< ", expected " << m_nbComponents);
}
void Step::checkNbValues(const int& nbValues)
throw (XAO_Exception)
{
if (nbValues == m_nbElements * m_nbComponents)
return;
throw XAO_Exception(MsgBuilder() << "Invalid number of values:" << nbValues
<< ", expected " << m_nbElements * m_nbComponents);
}

152
src/XAO/XAO_Step.hxx Normal file
View File

@ -0,0 +1,152 @@
// 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_STEP_HXX__
#define __XAO_STEP_HXX__
#include "XAO_XaoUtils.hxx"
namespace XAO
{
/**
* @class Step
* Base class for steps.
*/
class Step
{
protected:
/** Default constructor. */
Step() {}
public:
/**
* Destructor.
*/
virtual ~Step() {}
/**
* Gets the type of the step.
* @return
*/
virtual const XAO::Type getType() = 0;
/**
* Gets the step index.
* @return the index of the step.
*/
const int getStep() { return m_step; }
/**
* Sets the number of the step.
* @param step the index to set.
*/
void setStep(const int& step) { m_step = step; }
/**
* Gets the stamp of the index.
* @return the stamp of the index.
*/
const int getStamp() { return m_stamp; }
/**
* Sets the stamp of the index.
* @param stamp the stamp to set.
*/
void setStamp(const int& stamp) { m_stamp = stamp; }
/**
* Gets the number of components of the step.
* @return the number of components.
*/
const int countComponents() { return m_nbComponents; }
/**
* Gets the number of elements for the step.
* @return the number of elements.
*/
const int countElements() { return m_nbElements; }
/**
* Gets the number of values for the step.
* @return the number of values.
*/
const int countValues() { return m_nbElements * m_nbComponents; }
/**
* Gets a value as a string.
* @param element the index of the element.
* @param component the index of the component.
* @return the value as a string.
*/
virtual const std::string getStringValue(const int& element, const int& component) = 0;
/**
* Sets a value as a string
* @param element the index of the element.
* @param component the index of the component.
* @param value the string value.
* @throw XAO_Exception if the value is not valid.
*/
virtual void setStringValue(const int& element, const int& component, const std::string& value) = 0;
protected:
/**
* Checks that given element index is in the range of element indexes.
* @param element the index to check.
*/
void checkElementIndex(const int& element) throw (XAO_Exception);
/**
* Checks that given component index is in the range of component indexes.
* @param component the index to check.
*/
void checkComponentIndex(const int& component)throw (XAO_Exception);
/**
* Checks that the given number of elements is correct.
* @param nbElements the number of elements to check.
*/
void checkNbElements(const int& nbElements)throw (XAO_Exception);
/**
* Checks that the given number of components is correct.
* @param nbComponents the number of components to check.
*/
void checkNbComponents(const int& nbComponents)throw (XAO_Exception);
/**
* checks that the given number of values is correct.
* @param nbValues the number of values to check.
*/
void checkNbValues(const int& nbValues)throw (XAO_Exception);
protected:
/** the index of the step. */
int m_step;
/** The stamp of the step. */
int m_stamp;
/** The number of components. */
int m_nbComponents;
/** The number of elements. */
int m_nbElements;
};
}
#endif /* __XAO_STEP_HXX__ */

View File

@ -0,0 +1,60 @@
// 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 "XAO_StringField.hxx"
#include "XAO_StringStep.hxx"
#include "XAO_XaoUtils.hxx"
using namespace XAO;
StringField::StringField(const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents, const std::string& name)
: Field(dimension, nbElements, nbComponents, name)
{
}
Step* StringField::addNewStep(const int& step)
throw (XAO_Exception)
{
return addStep(step, 0);
}
StringStep* StringField::addStep(const int& step)
throw (XAO_Exception)
{
return addStep(step, 0);
}
StringStep* StringField::addStep(const int& step, const int& stamp)
throw (XAO_Exception)
{
if (hasStep(step))
throw XAO_Exception(MsgBuilder() << "Step with number " << step << " already exists.");
StringStep* bstep = new StringStep(step, stamp, m_nbElements, m_nbComponents);
m_steps.push_back(bstep);
return bstep;
}
StringStep* StringField::getStep(const int& index)
throw (XAO_Exception)
{
checkStepIndex(index);
return (StringStep*)m_steps[index];
}

View File

@ -0,0 +1,76 @@
// 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_STRINGFIELD_HXX__
#define __XAO_STRINGFIELD_HXX__
#include <string>
#include "XAO_XaoUtils.hxx"
#include "XAO_Field.hxx"
#include "XAO_StringStep.hxx"
namespace XAO
{
/**
* @class StringField
* Represents a field with string values.
*/
class StringField : public Field
{
public:
/**
* Constructor.
* @param dimension the dimension of the field.
* @param nbElements the number of elements.
* @param nbComponents the number of components.
* @param name the name of the field.
*/
StringField(const XAO::Dimension& dimension, const int& nbElements, const int& nbComponents, const std::string& name);
virtual const XAO::Type getType() { return XAO::STRING; }
virtual Step* addNewStep(const int& step) throw (XAO_Exception);
/**
* Adds a new step.
* @param step the number of the step.
* @return the newly created step.
*/
StringStep* addStep(const int& step) throw (XAO_Exception);
/**
* Adds a new step.
* @param step the number of the step.
* @param stamp the stamp of the step.
* @return the newly created step.
*/
StringStep* addStep(const int& step, const int& stamp) throw (XAO_Exception);
/**
* Gets the step of given index.
* @param index the index of the step.
* @return the step for the given index.
*/
StringStep* getStep(const int& index) throw (XAO_Exception);
};
}
#endif /* __XAO_STRINGFIELD_HXX__ */

147
src/XAO/XAO_StringStep.cxx Normal file
View File

@ -0,0 +1,147 @@
// 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 "XAO_StringStep.hxx"
using namespace XAO;
StringStep::StringStep(const int& step, const int& stamp, const int& nbElements, const int& nbComponents)
{
m_nbElements = nbElements;
m_nbComponents = nbComponents;
m_step = step;
m_stamp = stamp;
m_values.reserve(m_nbElements);
for (int i = 0; i < m_nbElements; ++i)
{
std::vector<std::string> row;
row.reserve(m_nbComponents);
for (int j = 0; j < m_nbComponents; ++j)
row.push_back("");
m_values.push_back(row);
}
}
std::vector<std::string> StringStep::getValues()
{
std::vector<std::string> result;
result.reserve(m_nbElements * m_nbComponents);
std::vector< std::vector<std::string> >::iterator it;
for (it = m_values.begin(); it != m_values.end(); ++it)
{
std::vector<std::string> eltValues = *it;
result.insert(result.end(), eltValues.begin(), eltValues.end());
}
return result;
}
std::vector<std::string> StringStep::getElement(const int& element)
throw (XAO_Exception)
{
checkElementIndex(element);
std::vector<std::string> result(m_values[element]);
return result;
}
std::vector<std::string> StringStep::getComponent(const int& component)
throw (XAO_Exception)
{
checkComponentIndex(component);
std::vector<std::string> result;
result.reserve(m_nbElements);
std::vector< std::vector<std::string> >::iterator it;
for (it = m_values.begin(); it != m_values.end(); ++it)
{
std::vector<std::string> eltValues = *it;
result.push_back(eltValues[component]);
}
return result;
}
const std::string StringStep::getValue(const int& element, const int& component)
throw (XAO_Exception)
{
checkElementIndex(element);
checkComponentIndex(component);
return m_values[element][component];
}
const std::string StringStep::getStringValue(const int& element, const int& component)
throw (XAO_Exception)
{
return getValue(element, component);
}
void StringStep::setValues(const std::vector<std::string>& values)
throw (XAO_Exception)
{
checkNbValues(values.size());
for (int i = 0; i < m_nbElements; ++i)
{
for (int j = 0; j < m_nbComponents; ++j)
{
m_values[i][j] = values[i * m_nbComponents + j];
}
}
}
void StringStep::setElement(const int& element, const std::vector<std::string>& elements)
throw (XAO_Exception)
{
checkElementIndex(element);
checkNbComponents(elements.size());
for (int i = 0; i < m_nbComponents; ++i)
m_values[element][i] = elements[i];
}
void StringStep::setComponent(const int& component, const std::vector<std::string>& components)
throw (XAO_Exception)
{
checkElementIndex(component);
checkNbElements(components.size());
for (int i = 0; i < m_nbElements; ++i)
m_values[i][component] = components[i];
}
void StringStep::setValue(const int& element, const int& component, const std::string& value)
throw (XAO_Exception)
{
checkElementIndex(element);
checkComponentIndex(component);
m_values[element][component] = value;
}
void StringStep::setStringValue(const int& element, const int& component, const std::string& value)
throw (XAO_Exception)
{
setValue(element, component, value);
}

115
src/XAO/XAO_StringStep.hxx Normal file
View File

@ -0,0 +1,115 @@
// 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_STRINGSTEP_HXX__
#define __XAO_STRINGSTEP_HXX__
#include <string>
#include <vector>
#include "XAO_XaoUtils.hxx"
#include "XAO_Step.hxx"
namespace XAO
{
/**
* @class StringStep
* Step with strings values.
*/
class StringStep : public Step
{
public:
/**
* Constructor.
* @param step the step number.
* @param stamp the stamp of the step.
* @param nbElements the number elements of the geometry.
* @param nbComponents the number of components of the field.
*/
StringStep(const int& step, const int& stamp, const int& nbElements, const int& nbComponents);
virtual const XAO::Type getType() { return XAO::STRING; }
/**
* Gets all the values of the step as a list.
* @return a vector containing all the values of the step.
*/
std::vector<std::string> getValues();
/**
* Gets all the values for a given element.
* @param element the index of the element.
* @return a vector containing all the values for the given element.
*/
std::vector<std::string> getElement(const int& element) throw (XAO_Exception);
/**
* Gets all the values for a given component.
* @param component the index of the component.
* @return a vector containing all the values for the given component.
*/
std::vector<std::string> getComponent(const int& component) throw (XAO_Exception);
/**
* Gets the value for an element and a component.
* @param element the index of the element.
* @param component the index of the component.
* @return the value for the given element and component.
*/
const std::string getValue(const int& element, const int& component) throw (XAO_Exception);
/**
* Sets all the values from a list.
* @param values the list of values to set.
*/
void setValues(const std::vector<std::string>& values) throw (XAO_Exception);
/**
* Sets the values for an element.
* @param element the index of the element to set.
* @param elements the values to set.
*/
void setElement(const int& element, const std::vector<std::string>& elements) throw (XAO_Exception);
/**
* Sets the values for a component.
* @param component the index of the component to set.
* @param components the values to set.
*/
void setComponent(const int& component, const std::vector<std::string>& components) throw (XAO_Exception);
/**
* Sets the value for an element and a component.
* @param element the index of the element.
* @param component the index of the component.
* @param value the value.
*/
void setValue(const int& element, const int& component, const std::string& value) throw (XAO_Exception);
virtual const std::string getStringValue(const int& element, const int& component) throw (XAO_Exception);
virtual void setStringValue(const int& element, const int& component, const std::string& value) throw (XAO_Exception);
private:
std::vector< std::vector<std::string> > m_values;
};
}
#endif /* __XAO_STRINGSTEP_HXX__ */

294
src/XAO/XAO_Xao.cxx Normal file
View File

@ -0,0 +1,294 @@
// 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 : Nathalie Gore (OpenCascade), Frederic Pons (OpenCascade)
#include <iostream>
#include "XAO_XaoUtils.hxx"
#include "XAO_Xao.hxx"
#include "XAO_Geometry.hxx"
#include "XAO_Group.hxx"
#include "XAO_Field.hxx"
#include "XAO_IntegerField.hxx"
#include "XAO_BooleanField.hxx"
#include "XAO_DoubleField.hxx"
#include "XAO_StringField.hxx"
#include "XAO_XaoExporter.hxx"
using namespace XAO;
const xmlChar* C_XAO_VERSION = (xmlChar*)"1.0";
Xao::Xao()
{
m_author = "";
m_version = (char*)C_XAO_VERSION;
m_geometry = NULL;
}
Xao::Xao(const std::string& author, const std::string& version)
{
m_author = author;
m_version = version;
m_geometry = NULL;
}
Xao::~Xao()
{
if (m_geometry != NULL)
{
delete m_geometry;
m_geometry = NULL;
}
for (std::list<Group*>::iterator it = m_groups.begin(); it != m_groups.end(); ++it)
{
delete (*it);
}
for (std::list<Field*>::iterator it = m_fields.begin(); it != m_fields.end(); ++it)
{
delete (*it);
}
}
const int Xao::countGroups() const
{
return m_groups.size();
}
Group* Xao::getGroup(const int& index)
throw (XAO_Exception)
{
checkGroupIndex(index);
int i = 0;
for (std::list<Group*>::iterator it = m_groups.begin(); it != m_groups.end(); ++it, ++i)
{
if (i == index)
return (*it);
}
return NULL;
}
Group* Xao::addGroup(const XAO::Dimension& dim, const std::string& name)
throw (XAO_Exception)
{
checkGeometry();
checkGroupDimension(dim);
Group* group = new Group(dim, m_geometry->countElements(dim), name);
m_groups.push_back(group);
return group;
}
bool Xao::removeGroup(Group* group)
{
int nb = countGroups();
m_groups.remove(group);
bool res = (nb-1 == countGroups());
if (res)
{
delete group;
group = NULL;
}
return res;
}
const int Xao::countFields() const
{
return m_fields.size();
}
const XAO::Type Xao::getFieldType(const int& index)
throw (XAO_Exception)
{
return getField(index)->getType();
}
Field* Xao::getField(const int& index)
throw (XAO_Exception)
{
checkFieldIndex(index);
int i = 0;
for (std::list<Field*>::iterator it = m_fields.begin(); it != m_fields.end(); ++it, ++i)
{
if (i == index)
return (*it);
}
throw XAO_Exception("Field not found.");
}
BooleanField* Xao::getBooleanField(const int& index)
throw (XAO_Exception)
{
Field* field = getField(index);
if (field->getType() != XAO::BOOLEAN)
throw XAO_Exception(MsgBuilder() << "Field " << index << " is not a boolean field.");
return (BooleanField*)field;
}
DoubleField* Xao::getDoubleField(const int& index)
throw (XAO_Exception)
{
Field* field = getField(index);
if (field->getType() != XAO::DOUBLE)
throw XAO_Exception(MsgBuilder() << "Field " << index << " is not a double field.");
return (DoubleField*)field;
}
IntegerField* Xao::getIntegerField(const int& index)
throw (XAO_Exception)
{
Field* field = getField(index);
if (field->getType() != XAO::INTEGER)
throw XAO_Exception(MsgBuilder() << "Field " << index << " is not an integer field.");
return (IntegerField*)field;
}
StringField* Xao::getStringField(const int& index)
throw (XAO_Exception)
{
Field* field = getField(index);
if (field->getType() != XAO::STRING)
throw XAO_Exception(MsgBuilder() << "Field " << index << " is not a string field.");
return (StringField*)field;
}
Field* Xao::addField(const XAO::Type& type, const XAO::Dimension& dim, const int& nbComponents, const std::string& name)
throw (XAO_Exception)
{
checkGeometry();
int nbElts = m_geometry->countElements(dim);
Field* field = Field::createField(type, dim, nbElts, nbComponents, name);
m_fields.push_back(field);
return field;
}
IntegerField* Xao::addIntegerField(const XAO::Dimension& dim, const int& nbComponents, const std::string& name)
throw (XAO_Exception)
{
checkGeometry();
int nbElts = m_geometry->countElements(dim);
IntegerField* field = new IntegerField(dim, nbElts, nbComponents, name);
m_fields.push_back(field);
return field;
}
BooleanField* Xao::addBooleanField(const XAO::Dimension& dim, const int& nbComponents, const std::string& name)
throw (XAO_Exception)
{
checkGeometry();
int nbElts = m_geometry->countElements(dim);
BooleanField* field = new BooleanField(dim, nbElts, nbComponents, name);
m_fields.push_back(field);
return field;
}
DoubleField* Xao::addDoubleField(const XAO::Dimension& dim, const int& nbComponents, const std::string& name)
throw (XAO_Exception)
{
checkGeometry();
int nbElts = m_geometry->countElements(dim);
DoubleField* field = new DoubleField(dim, nbElts, nbComponents, name);
m_fields.push_back(field);
return field;
}
StringField* Xao::addStringField(const XAO::Dimension& dim, const int& nbComponents, const std::string& name)
throw (XAO_Exception)
{
checkGeometry();
int nbElts = m_geometry->countElements(dim);
StringField* field = new StringField(dim, nbElts, nbComponents, name);
m_fields.push_back(field);
return field;
}
bool Xao::removeField(Field* field)
{
int nb = countFields();
m_fields.remove(field);
bool res = (nb-1 == countFields());
if (res)
{
delete field;
field = NULL;
}
return res;
}
const bool Xao::exportXAO(const std::string& fileName)
{
return XaoExporter::saveToFile(this, fileName);
}
const std::string Xao::getXML()
{
return XaoExporter::saveToXml(this);
}
const bool Xao::importXAO(const std::string& fileName)
{
return XaoExporter::readFromFile(fileName, this);
}
const bool Xao::setXML(const std::string& xml)
{
return XaoExporter::setXML(xml, this);
}
void Xao::checkGeometry() const
throw(XAO_Exception)
{
if (m_geometry == NULL)
throw XAO_Exception("Geometry is null");
}
void Xao::checkGroupIndex(const int& index) const
throw(XAO_Exception)
{
if (index >= 0 && index < countGroups())
return;
throw XAO_Exception(MsgBuilder() << "Group index is out of range [0, "
<< countGroups()-1 << "]: " << index);
}
void Xao::checkFieldIndex(const int& index) const
throw(XAO_Exception)
{
if (index >= 0 && index < countFields())
return;
throw XAO_Exception(MsgBuilder() << "Field index is out of range [0, "
<< countFields()-1 << "]: " << index);
}
void Xao::checkGroupDimension(const XAO::Dimension& dim) const
throw(XAO_Exception)
{
if (dim == XAO::WHOLE)
throw XAO_Exception(MsgBuilder() << "Invalid dimension for group: " << dim);
}

254
src/XAO/XAO_Xao.hxx Normal file
View File

@ -0,0 +1,254 @@
// 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 : Nathalie Gore (OpenCascade), Frederic Pons (OpenCascade)
#ifndef __XAO_XAO_HXX__
#define __XAO_XAO_HXX__
#include <string>
#include <list>
#include "XAO_Exception.hxx"
#include "XAO_XaoUtils.hxx"
#include "XAO_Geometry.hxx"
namespace XAO
{
class Group;
class Field;
class IntegerField;
class DoubleField;
class BooleanField;
class StringField;
/**
* @class Xao
* The Xao class describes the XAO format.
*/
class Xao
{
public:
/**
* Default constructor.
*/
Xao();
/**
* Constructor with author and version.
* \param author the author of the file.
* \param version the version of the XAO format.
*/
Xao(const std::string& author, const std::string& version);
/**
* Destructor.
*/
virtual ~Xao();
/**
* Gets the author of the file.
* \return the author of the file.
*/
const std::string getAuthor() const
{
return m_author;
}
/**
* Sets the author of the file.
* \param author the author to set.
*/
void setAuthor(const std::string& author)
{
m_author = author;
}
/**
* Gets the version of the file.
* \return the version of the file.
*/
const std::string getVersion() const
{
return m_version;
}
/**
* Sets the version of the file.
* \param version the version to set.
*/
void setVersion(const std::string& version)
{
m_version = version;
}
//
// Geometry
//
/**
* Gets the geometry.
* \return the geometry.
*/
Geometry* getGeometry() const
{
return m_geometry;
}
/**
* Sets the geometry.
* \param geometry the geometry to set.
*/
void setGeometry(Geometry* geometry) throw (XAO_Exception)
{
if (m_geometry != NULL)
throw XAO_Exception("Geometry already set.");
m_geometry = geometry;
m_geometry->setReadOnly();
}
//
// Groups
//
/**
* Gets the number of groups.
* \return the number of groups.
*/
const int countGroups() const;
/**
* Gets a group.
* \param index the index of the wanted group.
* \return the group.
*/
Group* getGroup(const int& index) throw (XAO_Exception);
/**
* Adds a group.
* \param dim the dimension of the group.
* \param name the name of the group.
* \return the created group.
*/
Group* addGroup(const XAO::Dimension& dim, const std::string& name = std::string("")) throw (XAO_Exception);
/**
* Removes a group.
* \param group the group to remove.
* \return true if the group has been removed, false otherwise.
*/
bool removeGroup(Group* group);
//
// Fields
//
/**
* Gets the number of fields.
* \return the number of fields.
*/
const int countFields() const;
/**
* Gets the type of a field.
* \param index the index of the wanted field.
* \return the type of the field.
*/
const XAO::Type getFieldType(const int& index) throw (XAO_Exception);
/**
* Gets a field.
* \param index the index of the wanted field.
* \return the field.
*/
Field* getField(const int& index) throw (XAO_Exception);
BooleanField* getBooleanField(const int& index) throw (XAO_Exception);
DoubleField* getDoubleField(const int& index) throw (XAO_Exception);
IntegerField* getIntegerField(const int& index) throw (XAO_Exception);
StringField* getStringField(const int& index) throw (XAO_Exception);
/**
* Adds a field.
* \param type the type of the field.
* \param dim the dimension of the field.
* \param nbComponents the number of components in the field.
* \param name the name of the field.
* \return the created field.
*/
Field* addField(const XAO::Type& type, const XAO::Dimension& dim, const int& nbComponents,
const std::string& name = std::string(""))
throw (XAO_Exception);
BooleanField* addBooleanField(const XAO::Dimension& dim, const int& nbComponents,
const std::string& name = std::string("")) throw (XAO_Exception);
IntegerField* addIntegerField(const XAO::Dimension& dim, const int& nbComponents,
const std::string& name = std::string("")) throw (XAO_Exception);
DoubleField* addDoubleField(const XAO::Dimension& dim, const int& nbComponents,
const std::string& name = std::string("")) throw (XAO_Exception);
StringField* addStringField(const XAO::Dimension& dim, const int& nbComponents,
const std::string& name = std::string("")) throw (XAO_Exception);
/**
* Removes a field.
* \param field the field to remove.
* \return true if the field has been removed, false otherwise.
*/
bool removeField(Field* field);
//
// Import / Export
//
/**
* Exports this XAO object to a file.
* \param fileName the name of the file to create.
* \return true is the export is successful.
*/
const bool exportXAO(const std::string& fileName);
/**
* Gets the XML corresponding to this XAO.
* \return the XML as a string.
*/
const std::string getXML();
/**
* Imports an XAO file into this object.
* \param fileName the name of the file to import.
* \return true if the import is successful.
*/
const bool importXAO(const std::string& fileName);
/**
* Sets an XML describing an XAO format to this object.
* \param xml the XML to set.
* \return true if the import is successful.
*/
const bool setXML(const std::string& xml);
private:
void checkGeometry() const throw (XAO_Exception);
void checkGroupIndex(const int& index) const throw (XAO_Exception);
void checkFieldIndex(const int& index) const throw (XAO_Exception);
void checkGroupDimension(const XAO::Dimension& dim) const throw (XAO_Exception);
private:
/** The author of the file. */
std::string m_author;
/** The version of the file. */
std::string m_version;
/** The geometry. */
Geometry* m_geometry;
/** The list of groups. */
std::list<Group*> m_groups;
/** The list of fields. */
std::list<Field*> m_fields;
};
}
#endif

626
src/XAO/XAO_XaoExporter.cxx Normal file
View File

@ -0,0 +1,626 @@
// 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 <libxml/parser.h>
#include "XAO_XaoExporter.hxx"
#include "XAO_Xao.hxx"
#include "XAO_Geometry.hxx"
#include "XAO_Group.hxx"
#include "XAO_Field.hxx"
#include "XAO_Step.hxx"
#include "XAO_XaoUtils.hxx"
namespace XAO
{
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_VALUE = (xmlChar*)"value";
const xmlChar* C_ATTR_VALUE_COMPONENT = (xmlChar*)"component";
const xmlChar* C_TAG_FIELDS = (xmlChar*)"fields";
const xmlChar* C_TAG_FIELD = (xmlChar*)"field";
const xmlChar* C_ATTR_FIELD_NAME = (xmlChar*)"name";
const xmlChar* C_ATTR_FIELD_TYPE = (xmlChar*)"type";
const xmlChar* C_ATTR_FIELD_DIMENSION = (xmlChar*)"dimension";
const xmlChar* C_TAG_COMPONENTS = (xmlChar*)"components";
const xmlChar* C_TAG_COMPONENT = (xmlChar*)"component";
const xmlChar* C_ATTR_COMPONENT_COLUMN = (xmlChar*)"column";
const xmlChar* C_ATTR_COMPONENT_NAME = (xmlChar*)"name";
const xmlChar* C_TAG_STEPS = (xmlChar*)"steps";
const xmlChar* C_TAG_STEP = (xmlChar*)"step";
const xmlChar* C_ATTR_STEP_NUMBER = (xmlChar*)"number";
const xmlChar* C_ATTR_STEP_STAMP = (xmlChar*)"stamp";
}
using namespace XAO;
std::string XaoExporter::readStringProp(xmlNodePtr node, const xmlChar* attribute,
const bool& required, const std::string& defaultValue,
const std::string& exception /*= std::string() */)
{
xmlChar* strAttr = xmlGetProp(node, attribute);
if (strAttr == NULL)
{
if (required)
{
if (exception.size() > 0)
throw XAO_Exception(exception.c_str());
throw XAO_Exception(MsgBuilder() << "Line " << node->line << ": "
<< "Property " << (char*)attribute << " is required.");
}
return defaultValue;
}
std::string res = (char*)strAttr;
xmlFree(strAttr);
return res;
}
int XaoExporter::readIntegerProp(xmlNodePtr node, const xmlChar* attribute,
const bool& required, const int& defaultValue,
const std::string& exception /*= std::string() */)
{
xmlChar* strAttr = xmlGetProp(node, attribute);
if (strAttr == NULL)
{
if (required)
{
if (exception.size() > 0)
throw XAO_Exception(exception.c_str());
throw XAO_Exception(MsgBuilder() << "Line " << node->line << ": "
<< "Property " << (char*)attribute << " is required.");
}
return defaultValue;
}
int res = XaoUtils::stringToInt((char*)strAttr);
xmlFree(strAttr);
return res;
}
const bool XaoExporter::saveToFile(Xao* xaoObject, const std::string& fileName)
throw (XAO_Exception)
{
xmlDocPtr doc = exportXMLDoc(xaoObject);
xmlSaveFormatFileEnc(fileName.c_str(), doc, "UTF-8", 1); // format = 1 for node indentation
xmlFreeDoc(doc);
return true;
}
const std::string XaoExporter::saveToXml(Xao* xaoObject)
throw (XAO_Exception)
{
xmlDocPtr doc = exportXMLDoc(xaoObject);
xmlChar *xmlbuff;
int buffersize;
xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1); // format = 1 for node indentation
xmlFreeDoc(doc);
xmlCleanupGlobals();
return (char*)xmlbuff;
}
xmlDocPtr XaoExporter::exportXMLDoc(Xao* xaoObject)
{
// 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 xaoObject->getVersion().c_str());
xmlNewProp(xao, C_ATTR_XAO_AUTHOR, BAD_CAST xaoObject->getAuthor().c_str());
if (xaoObject->getGeometry() != NULL)
{
exportGeometry(xaoObject->getGeometry(), masterDocument, xao);
}
exportGroups(xaoObject, xao);
exportFields(xaoObject, xao);
return masterDocument;
}
void XaoExporter::exportGeometricElements(Geometry* xaoGeometry,
xmlNodePtr topology, XAO::Dimension dim, const xmlChar* colTag, const xmlChar* eltTag)
{
xmlNodePtr vertices = xmlNewChild(topology, 0, colTag, 0);
xmlNewProp(vertices, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(xaoGeometry->countElements(dim)).c_str());
GeometricElementList::iterator it = xaoGeometry->begin(dim);
for (; it != xaoGeometry->end(dim); it++)
{
int index = it->first;
GeometricElement elt = it->second;
xmlNodePtr vertex = xmlNewChild(vertices, 0, eltTag, 0);
xmlNewProp(vertex, C_ATTR_ELT_INDEX, BAD_CAST XaoUtils::intToString(index).c_str());
xmlNewProp(vertex, C_ATTR_ELT_NAME, BAD_CAST elt.getName().c_str());
xmlNewProp(vertex, C_ATTR_ELT_REFERENCE, BAD_CAST elt.getReference().c_str());
}
}
void XaoExporter::exportGeometry(Geometry* xaoGeometry, xmlDocPtr doc, xmlNodePtr xao)
{
// Geometric part
xmlNodePtr geometry = xmlNewChild(xao, 0, C_TAG_GEOMETRY, 0);
xmlNewProp(geometry, C_ATTR_GEOMETRY_NAME, BAD_CAST xaoGeometry->getName().c_str());
xmlNodePtr shape = xmlNewChild(geometry, 0, C_TAG_SHAPE, 0);
xmlNewProp(shape, C_ATTR_SHAPE_FORMAT, BAD_CAST XaoUtils::shapeFormatToString(xaoGeometry->getFormat()).c_str());
std::string txtShape = xaoGeometry->getShapeString();
xmlNodePtr cdata = xmlNewCDataBlock(doc, BAD_CAST txtShape.c_str(), txtShape.size());
xmlAddChild(shape, cdata);
xmlNodePtr topology = xmlNewChild(geometry, 0, C_TAG_TOPOLOGY, 0);
exportGeometricElements(xaoGeometry, topology, XAO::VERTEX, C_TAG_VERTICES, C_TAG_VERTEX);
exportGeometricElements(xaoGeometry, topology, XAO::EDGE, C_TAG_EDGES, C_TAG_EDGE);
exportGeometricElements(xaoGeometry, topology, XAO::FACE, C_TAG_FACES, C_TAG_FACE);
exportGeometricElements(xaoGeometry, topology, XAO::SOLID, C_TAG_SOLIDS, C_TAG_SOLID);
}
void XaoExporter::exportGroups(Xao* xaoObject, xmlNodePtr xao)
{
xmlNodePtr groups = xmlNewChild(xao, 0, C_TAG_GROUPS, 0);
xmlNewProp(groups, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(xaoObject->countGroups()).c_str());
for (int i = 0; i < xaoObject->countGroups(); i++)
{
//Group* grp = (*it);
Group* grp = xaoObject->getGroup(i);
xmlNodePtr group = xmlNewChild(groups, 0, C_TAG_GROUP, 0);
xmlNewProp(group, C_ATTR_GROUP_NAME, BAD_CAST grp->getName().c_str());
xmlNewProp(group, C_ATTR_GROUP_DIM, BAD_CAST XaoUtils::dimensionToString(grp->getDimension()).c_str());
xmlNewProp(group, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(grp->count()).c_str());
for (std::set<int>::iterator it = grp->begin(); it != grp->end(); ++it)
{
int grpElt = (*it);
xmlNodePtr elt = xmlNewChild(group, 0, C_TAG_ELEMENT, 0);
xmlNewProp(elt, C_ATTR_ELEMENT_INDEX, BAD_CAST XaoUtils::intToString(grpElt).c_str());
}
}
}
void XaoExporter::exportFields(Xao* xaoObject, xmlNodePtr xao)
{
xmlNodePtr fields = xmlNewChild(xao, 0, C_TAG_FIELDS, 0);
xmlNewProp(fields, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(xaoObject->countFields()).c_str());
for (int i = 0; i < xaoObject->countFields(); i++)
{
Field* field = xaoObject->getField(i);
xmlNodePtr nodeField = xmlNewChild(fields, 0, C_TAG_FIELD, 0);
xmlNewProp(nodeField, C_ATTR_FIELD_NAME, BAD_CAST field->getName().c_str());
xmlNewProp(nodeField, C_ATTR_FIELD_TYPE, BAD_CAST XaoUtils::fieldTypeToString(field->getType()).c_str());
xmlNewProp(nodeField, C_ATTR_FIELD_DIMENSION, BAD_CAST XaoUtils::dimensionToString(field->getDimension()).c_str());
int nbComponents = field->countComponents();
xmlNodePtr components = xmlNewChild(nodeField, 0, C_TAG_COMPONENTS, 0);
xmlNewProp(components, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(nbComponents).c_str());
for (int j = 0; j < nbComponents; j++)
{
xmlNodePtr nodeComponent = xmlNewChild(components, 0, C_TAG_COMPONENT, 0);
xmlNewProp(nodeComponent, C_ATTR_COMPONENT_COLUMN, BAD_CAST XaoUtils::intToString(j).c_str());
xmlNewProp(nodeComponent, C_ATTR_COMPONENT_NAME, BAD_CAST field->getComponentName(j).c_str());
}
int nbSteps = field->countSteps();
xmlNodePtr nodeSteps = xmlNewChild(nodeField, 0, C_TAG_STEPS, 0);
xmlNewProp(nodeSteps, C_ATTR_COUNT, BAD_CAST XaoUtils::intToString(nbSteps).c_str());
for (stepIterator itStep = field->begin(); itStep != field->end(); itStep++)
{
Step* step = *itStep;
exportStep(step, field, nodeSteps);
}
}
}
void XaoExporter::exportStep(Step* step, Field* field, xmlNodePtr nodeSteps)
{
xmlNodePtr nodeStep = xmlNewChild(nodeSteps, 0, C_TAG_STEP, 0);
xmlNewProp(nodeStep, C_ATTR_STEP_NUMBER, BAD_CAST XaoUtils::intToString(step->getStep()).c_str());
if (step->getStamp() >= 0)
{
xmlNewProp(nodeStep, C_ATTR_STEP_STAMP, BAD_CAST XaoUtils::intToString(step->getStamp()).c_str());
}
for(int i = 0; i < step->countElements(); ++i)
{
xmlNodePtr nodeElt = xmlNewChild(nodeStep, 0, C_TAG_ELEMENT, 0);
xmlNewProp(nodeElt, C_ATTR_ELEMENT_INDEX, BAD_CAST XaoUtils::intToString(i).c_str());
for (int j = 0; j < step->countComponents(); ++j)
{
std::string content = step->getStringValue(i, j);
xmlNodePtr nodeValue = xmlNewChild(nodeElt, NULL, C_TAG_VALUE, BAD_CAST content.c_str());
xmlNewProp(nodeValue, C_ATTR_VALUE_COMPONENT, BAD_CAST XaoUtils::intToString(j).c_str());
}
}
}
const bool XaoExporter::readFromFile(const std::string& fileName, Xao* xaoObject)
throw (XAO_Exception)
{
// parse the file and get the DOM
int options = XML_PARSE_HUGE || XML_PARSE_NOCDATA;
xmlDocPtr doc = xmlReadFile(fileName.c_str(), NULL, options);
if (doc == NULL)
{
throw XAO_Exception("Cannot read XAO file");
}
parseXMLDoc(doc, xaoObject);
return true;
}
const bool XaoExporter::setXML(const std::string& xml, Xao* xaoObject)
throw (XAO_Exception)
{
int options = XML_PARSE_HUGE || XML_PARSE_NOCDATA;
xmlDocPtr doc = xmlReadDoc(BAD_CAST xml.c_str(), "", NULL, options);
if (doc == NULL)
{
throw XAO_Exception("Cannot read XAO stream");
}
parseXMLDoc(doc, xaoObject);
return true;
}
void XaoExporter::parseXMLDoc(xmlDocPtr doc, Xao* xaoObject)
{
// Get the root element node
xmlNodePtr root = xmlDocGetRootElement(doc);
if (xmlStrcmp(root->name , C_TAG_XAO) != 0)
throw XAO_Exception("Cannot read XAO file: invalid format XAO node not found");
parseXaoNode(doc, root, xaoObject);
xmlFreeDoc(doc); // free document
xmlCleanupParser(); // free globals
}
void XaoExporter::parseXaoNode(xmlDocPtr doc, xmlNodePtr xaoNode, Xao* xaoObject)
{
std::string version = readStringProp(xaoNode, C_ATTR_XAO_VERSION, false, "");
if (version != "")
xaoObject->setAuthor(version);
std::string author = readStringProp(xaoNode, C_ATTR_XAO_AUTHOR, false, "");
xaoObject->setAuthor(author);
for (xmlNodePtr node = xaoNode->children; node; node = node->next)
{
if (xmlStrcmp(node->name, C_TAG_GEOMETRY) == 0)
parseGeometryNode(doc, node, xaoObject);
else if (xmlStrcmp(node->name, C_TAG_GROUPS) == 0)
parseGroupsNode(node, xaoObject);
else if (xmlStrcmp(node->name, C_TAG_FIELDS) == 0)
parseFieldsNode(node, xaoObject);
}
}
void XaoExporter::parseGeometryNode(xmlDocPtr doc, xmlNodePtr geometryNode, Xao* xaoObject)
{
// get the shape and topo nodes
xmlNodePtr shapeNode = NULL;
xmlNodePtr topoNode = NULL;
for (xmlNodePtr node = geometryNode->children; node; node = node->next)
{
if (xmlStrcmp(node->name, C_TAG_SHAPE) == 0)
shapeNode = node;
else if (xmlStrcmp(node->name, C_TAG_TOPOLOGY) == 0)
topoNode = node;
}
std::string name = readStringProp(geometryNode, C_ATTR_GEOMETRY_NAME, false, "");
std::string strFormat = readStringProp(shapeNode, C_ATTR_SHAPE_FORMAT, true, "");
XAO::Format shapeFormat = XaoUtils::stringToShapeFormat(strFormat);
Geometry* geometry = Geometry::createGeometry(shapeFormat, name);
parseShapeNode(doc, shapeNode, geometry);
parseTopologyNode(topoNode, geometry);
xaoObject->setGeometry(geometry);
}
void XaoExporter::parseShapeNode(xmlDocPtr doc, xmlNodePtr shapeNode, Geometry* geometry)
{
if (geometry->getFormat() == XAO::BREP)
{
xmlChar* data = xmlNodeGetContent(shapeNode->children);
if (data == NULL)
throw XAO_Exception("Missing BREP");
geometry->setShapeString((char*)data);
xmlFree(data);
}
else
{
throw XAO_Exception(MsgBuilder() << "Shape format not supported: "
<< XaoUtils::shapeFormatToString(geometry->getFormat()));
}
}
void XaoExporter::parseTopologyNode(xmlNodePtr topologyNode, Geometry* geometry)
{
for (xmlNodePtr node = topologyNode->children; node; node = node->next)
{
if (xmlStrcmp(node->name, C_TAG_VERTICES) == 0)
parseVerticesNode(node, geometry);
else if (xmlStrcmp(node->name, C_TAG_EDGES) == 0)
parseEdgesNode(node, geometry);
else if (xmlStrcmp(node->name, C_TAG_FACES) == 0)
parseFacesNode(node, geometry);
else if (xmlStrcmp(node->name, C_TAG_SOLIDS) == 0)
parseSolidsNode(node, geometry);
}
}
void XaoExporter::parseVerticesNode(xmlNodePtr verticesNode, Geometry* geometry)
{
int count = readIntegerProp(verticesNode, C_ATTR_COUNT, true, -1);
geometry->setCountVertices(count);
for (xmlNodePtr node = verticesNode->children; node; node = node->next)
{
if (xmlStrcmp(node->name, C_TAG_VERTEX) == 0)
{
int index = readIntegerProp(node, C_ATTR_ELT_INDEX, true, -1);
std::string name = readStringProp(node, C_ATTR_ELT_NAME, false, "");
std::string reference = readStringProp(node, C_ATTR_ELT_REFERENCE, true, "");
geometry->setVertex(index, name, reference);
}
}
}
void XaoExporter::parseEdgesNode(xmlNodePtr edgesNode, Geometry* geometry)
{
int count = readIntegerProp(edgesNode, C_ATTR_COUNT, true, -1);
geometry->setCountEdges(count);
for (xmlNodePtr node = edgesNode->children; node; node = node->next)
{
if (xmlStrcmp(node->name, C_TAG_EDGE) == 0)
{
int index = readIntegerProp(node, C_ATTR_ELT_INDEX, true, -1);
std::string name = readStringProp(node, C_ATTR_ELT_NAME, false, "");
std::string reference = readStringProp(node, C_ATTR_ELT_REFERENCE, true, "");
geometry->setEdge(index, name, reference);
}
}
}
void XaoExporter::parseFacesNode(xmlNodePtr facesNode, Geometry* geometry)
{
int count = readIntegerProp(facesNode, C_ATTR_COUNT, true, -1);
geometry->setCountFaces(count);
for (xmlNodePtr node = facesNode->children; node; node = node->next)
{
if (xmlStrcmp(node->name, C_TAG_FACE) == 0)
{
int index = readIntegerProp(node, C_ATTR_ELT_INDEX, true, -1);
std::string name = readStringProp(node, C_ATTR_ELT_NAME, false, "");
std::string reference = readStringProp(node, C_ATTR_ELT_REFERENCE, true, "");
geometry->setFace(index, name, reference);
}
}
}
void XaoExporter::parseSolidsNode(xmlNodePtr solidsNode, Geometry* geometry)
{
int count = readIntegerProp(solidsNode, C_ATTR_COUNT, true, -1);
geometry->setCountSolids(count);
for (xmlNodePtr node = solidsNode->children; node; node = node->next)
{
if (xmlStrcmp(node->name, C_TAG_SOLID) == 0)
{
int index = readIntegerProp(node, C_ATTR_ELT_INDEX, true, -1);
std::string name = readStringProp(node, C_ATTR_ELT_NAME, false, "");
std::string reference = readStringProp(node, C_ATTR_ELT_REFERENCE, true, "");
geometry->setSolid(index, name, reference);
}
}
}
void XaoExporter::parseGroupsNode(xmlNodePtr groupsNode, Xao* xaoObject)
{
for (xmlNodePtr node = groupsNode->children; node; node = node->next)
{
if (xmlStrcmp(node->name, C_TAG_GROUP) == 0)
{
parseGroupNode(node, xaoObject);
}
}
}
void XaoExporter::parseGroupNode(xmlNodePtr groupNode, Xao* xaoObject)
{
std::string strDimension = readStringProp(groupNode, C_ATTR_GROUP_DIM, true, "");
XAO::Dimension dim = XaoUtils::stringToDimension(strDimension);
Group* group = xaoObject->addGroup(dim);
std::string name = readStringProp(groupNode, C_ATTR_GROUP_NAME, false, "");
group->setName(name);
for (xmlNodePtr node = groupNode->children; node; node = node->next)
{
if (xmlStrcmp(node->name, C_TAG_ELEMENT) == 0)
{
int index = readIntegerProp(node, C_ATTR_ELEMENT_INDEX, true, -1);
group->add(index);
}
}
}
void XaoExporter::parseFieldsNode(xmlNodePtr fieldsNode, Xao* xaoObject)
{
for (xmlNodePtr node = fieldsNode->children; node; node = node->next)
{
if (xmlStrcmp(node->name, C_TAG_FIELD) == 0)
{
parseFieldNode(node, xaoObject);
}
}
}
void XaoExporter::parseFieldNode(xmlNodePtr fieldNode, Xao* xaoObject)
{
std::string strDimension = readStringProp(fieldNode, C_ATTR_FIELD_DIMENSION, true, "");
XAO::Dimension dim = XaoUtils::stringToDimension(strDimension);
std::string strType = readStringProp(fieldNode, C_ATTR_FIELD_TYPE, true, "");
XAO::Type type = XaoUtils::stringToFieldType(strType);
// we need to get the number of components first to create the field
xmlNodePtr componentsNode = NULL;
xmlNodePtr stepsNode = NULL;
for (xmlNodePtr node = fieldNode->children; node; node = node->next)
{
if (xmlStrcmp(node->name, C_TAG_COMPONENTS) == 0)
componentsNode = node;
else if (xmlStrcmp(node->name, C_TAG_STEPS) == 0)
stepsNode = node;
}
// ensure that the components node is defined
if (componentsNode == NULL)
{
throw XAO_Exception(MsgBuilder() << "Line " << fieldNode->line << ": "
<< "No components defined for field.");
}
// create the field
int nbComponents = readIntegerProp(componentsNode, C_ATTR_COUNT, true, -1);
Field* field = xaoObject->addField(type, dim, nbComponents);
// parse the components
for (xmlNodePtr compNode = componentsNode->children; compNode; compNode = compNode->next)
{
std::string compName= readStringProp(compNode, C_ATTR_COMPONENT_NAME, false, "");
if (compName.size() > 0)
{
int col = readIntegerProp(compNode, C_ATTR_COMPONENT_COLUMN, true, -1);
field->setComponentName(col, compName);
}
}
// set the name
std::string name = readStringProp(fieldNode, C_ATTR_FIELD_NAME, false, "");
if (name.size() > 0) field->setName(name);
// read the steps
if (stepsNode != 0)
{
for (xmlNodePtr stepNode = stepsNode->children; stepNode; stepNode = stepNode->next)
{
if (xmlStrcmp(stepNode->name, C_TAG_STEP) == 0)
{
parseStepNode(stepNode, field);
}
}
}
}
void XaoExporter::parseStepNode(xmlNodePtr stepNode, Field* field)
{
int stepNumber = readIntegerProp(stepNode, C_ATTR_STEP_NUMBER, true, -1);
Step* step = field->addNewStep(stepNumber);
int stepStamp = readIntegerProp(stepNode, C_ATTR_STEP_STAMP, false, -1);
if (stepStamp != -1)
{
step->setStamp(stepStamp);
}
for (xmlNodePtr eltNode = stepNode->children; eltNode; eltNode = eltNode->next)
{
if (xmlStrcmp(eltNode->name, C_TAG_ELEMENT) == 0)
{
parseStepElementNode(eltNode, step);
}
}
}
void XaoExporter::parseStepElementNode(xmlNodePtr eltNode, Step* step)
{
int index = readIntegerProp(eltNode, C_ATTR_ELT_INDEX, true, -1);
for (xmlNodePtr valNode = eltNode->children; valNode; valNode = valNode->next)
{
if (xmlStrcmp(valNode->name, C_TAG_VALUE) == 0)
{
int component = readIntegerProp(valNode, C_ATTR_VALUE_COMPONENT, true, -1);
xmlChar* data = xmlNodeGetContent(valNode->children);
if (data == NULL)
{
throw XAO_Exception(MsgBuilder() << "Line " << valNode->line << ": no content for value.");
}
std::string value = (char*)data;
step->setStringValue(index, component, value);
}
}
}

109
src/XAO/XAO_XaoExporter.hxx Normal file
View File

@ -0,0 +1,109 @@
// 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_XAOEXPORTER_HXX__
#define __XAO_XAOEXPORTER_HXX__
#include <libxml/parser.h>
#include "XAO_Xao.hxx"
#include "XAO_Geometry.hxx"
#include "XAO_Group.hxx"
#include "XAO_Field.hxx"
namespace XAO
{
/**
* @class XaoExporter
* Util class for import/export XAO.
*/
class XaoExporter
{
public:
/**
* Saves the XAO object to a file.
* @param xaoObject the object to export.
* @param fileName the path of the file to create.
* @return true if the export was successful, false otherwise.
*/
static const bool saveToFile(Xao* xaoObject, const std::string& fileName)
throw (XAO_Exception);
/**
* Saves the XAO object to a XML string.
* @param xaoObject the object to export.
* @return the XML string.
*/
static const std::string saveToXml(Xao* xaoObject)
throw (XAO_Exception);
/**
* Reads a XAO object from a file.
* @param fileName the path of the file to read.
* @param xaoObject the XAO object.
* @return true if the XAO object was read successful, false otherwise.
*/
static const bool readFromFile(const std::string& fileName, Xao* xaoObject)
throw (XAO_Exception);
/**
* Reads a XAO object from an XML string.
* @param xml the XML string.
* @param xaoObject the XAO object.
* @return true if the XAO object was read successful, false otherwise.
*/
static const bool setXML(const std::string& xml, Xao* xaoObject)
throw (XAO_Exception);
private:
static xmlDocPtr exportXMLDoc(Xao* xaoObject);
static void exportGeometry(Geometry* xaoGeometry, xmlDocPtr doc, xmlNodePtr xao);
static void exportGeometricElements(Geometry* xaoGeometry, xmlNodePtr topology,
XAO::Dimension dim, const xmlChar* colTag, const xmlChar* eltTag);
static void exportGroups(Xao* xaoObject, xmlNodePtr xao);
static void exportFields(Xao* xaoObject, xmlNodePtr xao);
static void exportStep(Step* step, Field* field, xmlNodePtr nodeSteps);
static void parseXMLDoc(xmlDocPtr doc, Xao* xaoObject);
static void parseXaoNode(xmlDocPtr doc, xmlNodePtr xaoNode, Xao* xaoObject);
static void parseGeometryNode(xmlDocPtr doc, xmlNodePtr geometryNode, Xao* xaoObject);
static void parseShapeNode(xmlDocPtr doc, xmlNodePtr shapeNode, Geometry* geometry);
static void parseTopologyNode(xmlNodePtr topologyNode, Geometry* geometry);
static void parseVerticesNode(xmlNodePtr verticesNode, Geometry* geometry);
static void parseEdgesNode(xmlNodePtr edgesNode, Geometry* geometry);
static void parseFacesNode(xmlNodePtr facesNode, Geometry* geometry);
static void parseSolidsNode(xmlNodePtr solidsNode, Geometry* geometry);
static void parseGroupsNode(xmlNodePtr groupsNode, Xao* xaoObject);
static void parseGroupNode(xmlNodePtr groupNode, Xao* xaoObject);
static void parseFieldsNode(xmlNodePtr fieldsNode, Xao* xaoObject);
static void parseFieldNode(xmlNodePtr fieldNode, Xao* xaoObject);
static void parseStepNode(xmlNodePtr stepNode, Field* field);
static void parseStepElementNode(xmlNodePtr eltNode, Step* step);
static std::string readStringProp(xmlNodePtr node, const xmlChar* attribute,
const bool& required, const std::string& defaultValue, const std::string& exception = std::string(""));
static int readIntegerProp(xmlNodePtr node, const xmlChar* attribute,
const bool& required, const int& defaultValue, const std::string& exception = std::string(""));
};
}
#endif /* __XAO_XAOEXPORTER_HXX__ */

165
src/XAO/XAO_XaoUtils.cxx Normal file
View File

@ -0,0 +1,165 @@
// 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 <sstream>
#include "XAO_Xao.hxx"
#include "XAO_XaoUtils.hxx"
using namespace XAO;
const std::string XaoUtils::intToString(const int& value)
{
std::ostringstream str;
str << value;
return str.str();
}
const int XaoUtils::stringToInt(const std::string& value)
throw(XAO_Exception)
{
int res;
std::istringstream convert(value);
if ( !(convert >> res) )
throw XAO_Exception(MsgBuilder() << "Cannot convert '" << value << "' to integer.");
return res;
}
const std::string XaoUtils::doubleToString(const double& value)
{
std::ostringstream str;
str << value;
return str.str();
}
const double XaoUtils::stringToDouble(const std::string& value)
throw(XAO_Exception)
{
double res;
std::istringstream convert(value);
if ( !(convert >> res) )
throw XAO_Exception(MsgBuilder() << "Cannot convert '" << value << "' to double.");
return res;
}
const std::string XaoUtils::booleanToString(const bool& value)
{
if (value)
return "true";
return "false";
}
const bool XaoUtils::stringToBoolean(const std::string& value)
throw(XAO_Exception)
{
if (value == "true" || value == "1")
return true;
if (value == "false" || value == "0")
return false;
throw XAO_Exception(MsgBuilder() << "Invalid boolean value: " << value);
}
const std::string XaoUtils::dimensionToString(const XAO::Dimension& dimension)
throw(XAO_Exception)
{
if (dimension == XAO::VERTEX)
return "vertex";
if (dimension == XAO::EDGE)
return "edge";
if (dimension == XAO::FACE)
return "face";
if (dimension == XAO::SOLID)
return "solid";
if (dimension == XAO::WHOLE)
return "whole";
throw XAO_Exception(MsgBuilder() << "Bad dimension: " << dimension);
}
const XAO::Dimension XaoUtils::stringToDimension(const std::string& dimension)
throw(XAO_Exception)
{
if (dimension == "vertex")
return XAO::VERTEX;
if (dimension == "edge")
return XAO::EDGE;
if (dimension == "face")
return XAO::FACE;
if (dimension == "solid")
return XAO::SOLID;
if (dimension == "whole")
return XAO::WHOLE;
throw XAO_Exception(MsgBuilder() << "Bad dimension: " << dimension);
}
const std::string XaoUtils::fieldTypeToString(const XAO::Type& type)
throw(XAO_Exception)
{
if (type ==XAO:: BOOLEAN)
return "boolean";
if (type == XAO::INTEGER)
return "integer";
if (type == XAO::DOUBLE)
return "double";
if (type == XAO::STRING)
return "string";
throw XAO_Exception(MsgBuilder() << "Bad type: " << type);
}
const XAO::Type XaoUtils::stringToFieldType(const std::string& type)
throw(XAO_Exception)
{
if (type == "boolean")
return XAO::BOOLEAN;
if (type == "integer")
return XAO::INTEGER;
if (type == "double")
return XAO::DOUBLE;
if (type == "string")
return XAO::STRING;
throw XAO_Exception(MsgBuilder() << "Bad type: " << type);
}
const std::string XaoUtils::shapeFormatToString(const XAO::Format& format)
throw(XAO_Exception)
{
if (format == XAO::BREP)
return "BREP";
if (format == XAO::STEP)
return "STEP";
throw XAO_Exception(MsgBuilder() << "Bad format: " << format);
}
const XAO::Format XaoUtils::stringToShapeFormat(const std::string& format)
throw(XAO_Exception)
{
if (format == "BREP")
return XAO::BREP;
if (format == "STEP")
return XAO::STEP;
throw XAO_Exception(MsgBuilder() << "Bad format: " << format);
}

200
src/XAO/XAO_XaoUtils.hxx Normal file
View File

@ -0,0 +1,200 @@
// 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__
#include <sstream>
#include <string>
#include <exception>
#include "XAO_Exception.hxx"
namespace XAO
{
/**
* @enum Format
*/
enum Format
{
BREP,
STEP
};
/**
* @enum Dimension
*/
enum Dimension
{
VERTEX = 0,//!< VERTEX
EDGE = 1, //!< EDGE
FACE = 2, //!< FACE
SOLID = 3, //!< SOLID
WHOLE = -1 //!< WHOLE
};
/**
* @enum Type
*/
enum Type
{
BOOLEAN = 0,//!< BOOLEAN
INTEGER = 1,//!< INTEGER
DOUBLE = 2, //!< DOUBLE
STRING = 3 //!< STRING
};
/**
* \class XaoUtils
* Utilities class to convert types.
*/
class XaoUtils
{
public:
/**
* Converts an integer into a string.
* \param value the integer to convert.
* \return the string.
*/
static const std::string intToString(const int& value);
/**
* Converts a string into an integer.
* \param value the string to convert.
* \return the integer value.
* \throw XAO_Exception if value cannot be converted to string.
*/
static const int stringToInt(const std::string& value) throw(XAO_Exception);
/**
* Converts a double into a string.
* \param value the double to convert.
* \return the string.
*/
static const std::string doubleToString(const double& value);
/**
* Converts a string into a double.
* \param value the string to convert.
* \return the double value.
* \throw XAO_Exception if value cannot be converted to string.
*/
static const double stringToDouble(const std::string& value) throw(XAO_Exception);
/**
* Converts a boolean into a string.
* \param value the boolean to convert.
* \return the string.
*/
static const std::string booleanToString(const bool& value);
/**
* Converts a string into a boolean.
* \param value the string to convert.
* \return the boolean value.
* \throw XAO_Exception if value cannot be converted to boolean.
* \note accepted values are "true", "1", "false", "0".
*/
static const bool stringToBoolean(const std::string& value) throw(XAO_Exception);
/**
* Converts a Dimension to string.
* \param dimension the Dimension to convert.
* \return the dimension as a string.
* \throw XAO_Exception
*/
static const std::string dimensionToString(const XAO::Dimension& dimension) throw(XAO_Exception);
/**
* Converts a string into a Dimension.
* \param dimension the dimension as a string.
* \return the converted Dimension.
* \throw XAO_Exception if dimension cannot be converted.
*/
static const XAO::Dimension stringToDimension(const std::string& dimension) throw(XAO_Exception);
/**
* Converts a Type to string.
* \param type the Type to convert.
* \return the Type as a string.
* \throw XAO_Exception
*/
static const std::string fieldTypeToString(const XAO::Type& type) throw(XAO_Exception);
/**
* Converts a string into a Type.
* \param type the Type as a string.
* \return the converted Type.
* \throw XAO_Exception if type cannot be converted.
*/
static const XAO::Type stringToFieldType(const std::string& type) throw(XAO_Exception);
/**
* Converts a Format to string.
* \param format the Format to convert.
* \return the Format as a string.
* \throw XAO_Exception
*/
static const std::string shapeFormatToString(const XAO::Format& format) throw(XAO_Exception);
/**
* Converts a string into a Format.
* \param format the Format as a string.
* \return the converted Format.
* \throw XAO_Exception if format cannot be converted.
*/
static const XAO::Format stringToShapeFormat(const std::string& format) throw(XAO_Exception);
};
/**
* @class MsgBuilder
* MsgBuilder can be use to easily create messages.
*/
class MsgBuilder
{
public:
/** Constructor. */
MsgBuilder() {};
/** Destructor. */
~MsgBuilder() {};
#ifndef SWIG
/** Stream operator. */
template <typename T>
MsgBuilder& operator <<(const T& t)
{
m_stream << t;
return *this;
}
/**
* Conversion operator to char*.
*/
operator const char*() const { return m_stream.str().c_str(); }
#endif
private :
std::stringstream m_stream;
};
}
#endif /* __XAO_UTILS_HXX__ */

View File

@ -0,0 +1,305 @@
#include <vector>
#include "TestUtils.hxx"
#include "BrepGeometryTest.hxx"
#include "../XAO_XaoUtils.hxx"
#include "../XAO_Xao.hxx"
#include "../XAO_BrepGeometry.hxx"
using namespace XAO;
void BrepGeometryTest::setUp()
{
}
void BrepGeometryTest::tearDown()
{
}
void BrepGeometryTest::cleanUp()
{
}
void readBrep(Geometry* geom, const std::string& fileName)
{
char* txt = TestUtils::readTextFile(TestUtils::getTestFilePath(fileName));
geom->setShapeString(txt);
}
void BrepGeometryTest::testGetIDs()
{
BrepGeometry* geom = new BrepGeometry("box");
readBrep(geom, "Box_1.brep");
CPPUNIT_ASSERT_EQUAL(8, geom->countElements(XAO::VERTEX));
CPPUNIT_ASSERT_EQUAL(8, geom->countVertices());
int vertices[8] = { 6,7,9,11,16,17,19,21 };
for (int i = 0; i < 8; ++i)
CPPUNIT_ASSERT_EQUAL(vertices[i], geom->getVertexID(i));
CPPUNIT_ASSERT_EQUAL(12, geom->countElements(XAO::EDGE));
CPPUNIT_ASSERT_EQUAL(12, geom->countEdges());
int edges[12] = { 5,8,10,12,15,18,20,22,25,26,29,30 };
for (int i = 0; i < 12; ++i)
CPPUNIT_ASSERT_EQUAL(edges[i], geom->getEdgeID(i));
CPPUNIT_ASSERT_EQUAL(6, geom->countElements(XAO::FACE));
CPPUNIT_ASSERT_EQUAL(6, geom->countFaces());
int faces[6] = { 3,13,23,27,31,33 };
for (int i = 0; i < 6; ++i)
CPPUNIT_ASSERT_EQUAL(faces[i], geom->getFaceID(i));
CPPUNIT_ASSERT_EQUAL(1, geom->countElements(XAO::SOLID));
CPPUNIT_ASSERT_EQUAL(1, geom->countSolids());
CPPUNIT_ASSERT_EQUAL(1, geom->getSolidID(0));
delete geom;
}
void BrepGeometryTest::testGetReferences()
{
BrepGeometry* geom = new BrepGeometry("box");
readBrep(geom, "Box_1.brep");
// vertex of index 1 has id = 7
CPPUNIT_ASSERT_EQUAL(std::string("7"), geom->getElementReference(XAO::VERTEX, 1));
CPPUNIT_ASSERT_EQUAL(std::string("7"), geom->getVertexReference(1));
CPPUNIT_ASSERT_EQUAL(7, geom->getVertexID(1));
CPPUNIT_ASSERT_EQUAL(1, geom->getElementIndexByReference(XAO::VERTEX, "7"));
CPPUNIT_ASSERT_EQUAL(1, geom->findVertex(7));
// edge of index 1 has id = 8
CPPUNIT_ASSERT_EQUAL(std::string("8"), geom->getElementReference(XAO::EDGE, 1));
CPPUNIT_ASSERT_EQUAL(std::string("8"), geom->getEdgeReference(1));
CPPUNIT_ASSERT_EQUAL(8, geom->getEdgeID(1));
CPPUNIT_ASSERT_EQUAL(1, geom->getElementIndexByReference(XAO::EDGE, "8"));
CPPUNIT_ASSERT_EQUAL(1, geom->findEdge(8));
// face of index 1 has id = 13
CPPUNIT_ASSERT_EQUAL(std::string("13"), geom->getElementReference(XAO::FACE, 1));
CPPUNIT_ASSERT_EQUAL(std::string("13"), geom->getFaceReference(1));
CPPUNIT_ASSERT_EQUAL(13, geom->getFaceID(1));
CPPUNIT_ASSERT_EQUAL(1, geom->getElementIndexByReference(XAO::FACE, "13"));
CPPUNIT_ASSERT_EQUAL(1, geom->findFace(13));
// solid of index 0 has id = 1
CPPUNIT_ASSERT_EQUAL(std::string("1"), geom->getElementReference(XAO::SOLID, 0));
CPPUNIT_ASSERT_EQUAL(std::string("1"), geom->getSolidReference(0));
CPPUNIT_ASSERT_EQUAL(1, geom->getSolidID(0));
CPPUNIT_ASSERT_EQUAL(0, geom->getElementIndexByReference(XAO::SOLID, "1"));
CPPUNIT_ASSERT_EQUAL(0, geom->findSolid(1));
delete geom;
}
void BrepGeometryTest::testGetNames()
{
BrepGeometry* geom = new BrepGeometry("box");
readBrep(geom, "Box_1.brep");
int id;
// vertex of index 1 has id = 7
id = 7;
CPPUNIT_ASSERT_EQUAL(std::string(""), geom->findVertexName(id));
geom->changeVertexName(id, std::string("va"));
CPPUNIT_ASSERT_EQUAL(std::string("va"), geom->findVertexName(id));
CPPUNIT_ASSERT_THROW(geom->changeVertexName(100, "a"), XAO_Exception);
CPPUNIT_ASSERT_THROW(geom->findVertexName(100), XAO_Exception);
// edge of index 1 has id = 8
id = 8;
CPPUNIT_ASSERT_EQUAL(std::string(""), geom->findEdgeName(id));
geom->changeEdgeName(id, std::string("ea"));
CPPUNIT_ASSERT_EQUAL(std::string("ea"), geom->findEdgeName(id));
CPPUNIT_ASSERT_THROW(geom->changeEdgeName(100, "a"), XAO_Exception);
CPPUNIT_ASSERT_THROW(geom->findEdgeName(100), XAO_Exception);
// face of index 1 has id = 13
id = 13;
CPPUNIT_ASSERT_EQUAL(std::string(""), geom->findFaceName(id));
geom->changeFaceName(id, std::string("fa"));
CPPUNIT_ASSERT_EQUAL(std::string("fa"), geom->findFaceName(id));
CPPUNIT_ASSERT_THROW(geom->changeFaceName(100, "a"), XAO_Exception);
CPPUNIT_ASSERT_THROW(geom->findFaceName(100), XAO_Exception);
// solid of index 0 has id = 1
id = 1;
CPPUNIT_ASSERT_EQUAL(std::string(""), geom->findSolidName(id));
geom->changeSolidName(id, std::string("sa"));
CPPUNIT_ASSERT_EQUAL(std::string("sa"), geom->findSolidName(id));
CPPUNIT_ASSERT_THROW(geom->changeSolidName(100, "a"), XAO_Exception);
CPPUNIT_ASSERT_THROW(geom->findSolidName(100), XAO_Exception);
delete geom;
}
void BrepGeometryTest::testGetEdgeVertices()
{
BrepGeometry* geom = new BrepGeometry("box");
readBrep(geom, "Box_2.brep");
// edge of index 23, id = #63
// vertex are 47 (#12), 59 (#15)
int v1, v2;
geom->getEdgeVertices(23, v1, v2);
CPPUNIT_ASSERT_EQUAL(12, v1);
CPPUNIT_ASSERT_EQUAL(15, v2);
delete geom;
}
void printVector(std::vector<int>& v)
{
std::cout << "# ";
for (int i = 0; i < v.size(); i++)
std::cout << v[i] << ", ";
std::cout << std::endl;
}
void BrepGeometryTest::testGetFaceEdges()
{
BrepGeometry* geom = new BrepGeometry("box");
readBrep(geom, "Box_2.brep");
CPPUNIT_ASSERT_EQUAL(2, geom->countFaceWires(1)); // face 13
CPPUNIT_ASSERT_EQUAL(1, geom->countFaceWires(2)); // face 29
// wire 0 of face 1 (#13) => edge 4 (#15), 5 (#17), 0 (#5), 6 (#19)
std::vector<int> edges = geom->getFaceEdges(1, 0);
CPPUNIT_ASSERT_EQUAL(4, (int)edges.size());
int ids1[4] = { 4,5,0,6 };
for (int i = 0; i < 4; ++i)
CPPUNIT_ASSERT_EQUAL(ids1[i], edges[i]);
// wire 1 of face 13 => edge 7 (#21) ,8 (#24), 9 (#26), 10 (#28)
edges = geom->getFaceEdges(1, 1);
CPPUNIT_ASSERT_EQUAL(4, (int)edges.size());
int ids2[4] = { 7,8,9,10 };
for (int i = 0; i < 4; ++i)
CPPUNIT_ASSERT_EQUAL(ids2[i], edges[i]);
delete geom;
}
void BrepGeometryTest::testSolidFaces()
{
BrepGeometry* geom = new BrepGeometry("box");
readBrep(geom, "Cut_2.brep");
CPPUNIT_ASSERT_EQUAL(5, geom->countSolidShells(0));
std::vector<int> faces = geom->getSolidFaces(0, 0);
CPPUNIT_ASSERT_EQUAL(6, (int)faces.size());
int ids[6] = { 0, 1, 2, 3, 4, 5 };
for (int i = 0; i < 6; ++i)
CPPUNIT_ASSERT_EQUAL(ids[i], faces[i]);
faces = geom->getSolidFaces(0, 1);
CPPUNIT_ASSERT_EQUAL(6, (int)faces.size());
int ids2[6] = { 6, 7, 8, 9, 10, 11 };
for (int i = 0; i < 6; ++i)
CPPUNIT_ASSERT_EQUAL(ids2[i], faces[i]);
delete geom;
}
void BrepGeometryTest::testGetVertex()
{
BrepGeometry* geom = new BrepGeometry("box");
readBrep(geom, "Box_2.brep");
double x, y, z;
geom->getVertexXYZ(15, x, y, z);
CPPUNIT_ASSERT_DOUBLES_EQUAL(60., x, 1e-6);
CPPUNIT_ASSERT_DOUBLES_EQUAL(80., y, 1e-6);
CPPUNIT_ASSERT_DOUBLES_EQUAL(60., z, 1e-6);
delete geom;
}
void BrepGeometryTest::testGetEdgeLength()
{
BrepGeometry* geom = new BrepGeometry("box");
readBrep(geom, "Box_2.brep");
// edges 0 (#5), 7 (#21)
CPPUNIT_ASSERT_DOUBLES_EQUAL(200., geom->getEdgeLength(0), 0);
CPPUNIT_ASSERT_DOUBLES_EQUAL(80., geom->getEdgeLength(7), 0);
delete geom;
}
void BrepGeometryTest::testGetFaceArea()
{
BrepGeometry* geom = new BrepGeometry("box");
readBrep(geom, "Box_2.brep");
// faces 0 (#3), 1 (#13)
CPPUNIT_ASSERT_DOUBLES_EQUAL(40000., geom->getFaceArea(0), 1e-9);
CPPUNIT_ASSERT_DOUBLES_EQUAL(33600., geom->getFaceArea(1), 1e-9);
delete geom;
}
void BrepGeometryTest::testGetSolidVolume()
{
BrepGeometry* geom = new BrepGeometry("box");
readBrep(geom, "Box_2.brep");
CPPUNIT_ASSERT_DOUBLES_EQUAL(7488000., geom->getSolidVolume(0), 1e-9);
delete geom;
}
void BrepGeometryTest::testParse()
{
BrepGeometry* geom = new BrepGeometry("box");
readBrep(geom, "Box_2.brep");
std::cout << std::endl;
for (int solidIndex = 0; solidIndex < geom->countSolids(); ++solidIndex)
{
std::cout << "Solid #" << solidIndex << " : " << geom->getSolidReference(solidIndex) << std::endl;
int nbShells = geom->countSolidShells(solidIndex);
for (int shellIndex = 0; shellIndex < nbShells; ++shellIndex)
{
std::cout << " Shell #" << shellIndex << std::endl;
std::vector<int> faces = geom->getSolidFaces(solidIndex, shellIndex);
for (int indf = 0; indf < faces.size(); ++indf)
{
int faceIndex = faces[indf];
std::cout << " Face #" << geom->getFaceReference(faceIndex) << std::endl;
int nbWires = geom->countFaceWires(faceIndex);
for (int wireIndex = 0; wireIndex < nbWires; ++wireIndex)
{
std::cout << " Wire #" << wireIndex << std::endl;
std::vector<int> edges = geom->getFaceEdges(faceIndex, wireIndex);
for (int inde = 0; inde < edges.size(); ++inde)
{
int edgeIndex = edges[inde];
std::cout << " Edge #" << geom->getEdgeReference(edgeIndex) << " : ";
int va = 0, vb = 0;
geom->getEdgeVertices(edgeIndex, va, vb);
int vaRef = geom->getVertexID(va);
int vbRef = geom->getVertexID(vb);
double ax, ay, az, bx, by, bz;
geom->getVertexXYZ(va, ax, ay, az);
geom->getVertexXYZ(vb, bx, by, bz);
std::cout << vaRef << " (" << ax << ", " << ay << ", " << az << ")";
std::cout << " - ";
std::cout << vbRef << " (" << bx << ", " << by << ", " << bz << ")";
std::cout << std::endl;
}
}
}
}
}
delete geom;
}

View File

@ -0,0 +1,45 @@
#ifndef __XAO_BREPGEOMETRY_TEST_HXX__
#define __XAO_BREPGEOMETRY_TEST_HXX__
#include <cppunit/extensions/HelperMacros.h>
namespace XAO
{
class BrepGeometryTest: public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(BrepGeometryTest);
CPPUNIT_TEST(testGetIDs);
CPPUNIT_TEST(testGetReferences);
CPPUNIT_TEST(testGetNames);
CPPUNIT_TEST(testGetEdgeVertices);
CPPUNIT_TEST(testGetFaceEdges);
CPPUNIT_TEST(testSolidFaces);
CPPUNIT_TEST(testGetVertex);
CPPUNIT_TEST(testGetEdgeLength);
CPPUNIT_TEST(testGetFaceArea);
CPPUNIT_TEST(testGetSolidVolume);
CPPUNIT_TEST(testParse);
CPPUNIT_TEST_SUITE_END();
public:
void setUp();
void tearDown();
void cleanUp();
void testGetIDs();
void testGetReferences();
void testGetNames();
void testGetEdgeVertices();
void testGetFaceEdges();
void testSolidFaces();
void testGetVertex();
void testGetEdgeLength();
void testGetFaceArea();
void testGetSolidVolume();
void testParse();
};
}
#endif // __XAO_BREPGEOMETRY_TEST_HXX__

View File

@ -0,0 +1,62 @@
# Copyright (C) 2012-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
# 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
#
# --- options ---
# additional include directories
INCLUDE_DIRECTORIES(
${PTHREAD_INCLUDE_DIR}
${LIBXML2_INCLUDE_DIR}
${CAS_INCLUDE_DIRS}
${CPPUNIT_INCLUDE_DIRS}
)
# additional preprocessor / compiler flags
ADD_DEFINITIONS(
${LIBXML2_DEFINITIONS}
${CAS_DEFINITIONS}
${CPPUNIT_DEFINITIONS}
)
# libraries to link to
SET(_link_LIBRARIES
${CPPUNIT_LIBRARIES}
XAO
)
# --- sources ---
SET(TestXAO_SOURCES
BrepGeometryTest.cxx
FieldTest.cxx
GeometryTest.cxx
GroupTest.cxx
ImportExportTest.cxx
XAOTests.cxx
XaoTest.cxx
XaoUtilsTest.cxx
)
# --- rules ---
ADD_EXECUTABLE(TestXAO ${TestXAO_SOURCES})
TARGET_LINK_LIBRARIES(TestXAO ${_link_LIBRARIES})
ADD_TEST(TestXAO TestXAO)
INSTALL(TARGETS TestXAO DESTINATION ${SALOME_INSTALL_BINS})

480
src/XAO/tests/FieldTest.cxx Normal file
View File

@ -0,0 +1,480 @@
#include <vector>
#include "FieldTest.hxx"
#include "../XAO_Xao.hxx"
#include "../XAO_XaoUtils.hxx"
#include "../XAO_Field.hxx"
#include "../XAO_Step.hxx"
#include "../XAO_BooleanField.hxx"
#include "../XAO_IntegerField.hxx"
#include "../XAO_DoubleField.hxx"
#include "../XAO_StringField.hxx"
using namespace XAO;
void FieldTest::setUp()
{
}
void FieldTest::tearDown()
{
}
void FieldTest::cleanUp()
{
}
Field* FieldTest::testField(XAO::Type type)
{
Field* f = Field::createField(type, XAO::FACE, 10, 3);
CPPUNIT_ASSERT_EQUAL(0, (int)f->getName().size());
CPPUNIT_ASSERT_EQUAL(type, f->getType());
CPPUNIT_ASSERT_EQUAL(XAO::FACE, f->getDimension());
CPPUNIT_ASSERT_EQUAL(3, f->countComponents());
CPPUNIT_ASSERT_EQUAL(10, f->countElements());
CPPUNIT_ASSERT_EQUAL(30, f->countValues());
f->setName("field1");
CPPUNIT_ASSERT_EQUAL(std::string("field1"), f->getName());
CPPUNIT_ASSERT_EQUAL(0, (int)f->getComponentName(0).size());
f->setComponentName(0, "x");
f->setComponentName(1, "y");
f->setComponentName(2, "z");
CPPUNIT_ASSERT_EQUAL(3, f->countComponents());
CPPUNIT_ASSERT_EQUAL(std::string("x"), f->getComponentName(0));
CPPUNIT_ASSERT_EQUAL(std::string("y"), f->getComponentName(1));
CPPUNIT_ASSERT_EQUAL(std::string("z"), f->getComponentName(2));
CPPUNIT_ASSERT_THROW(f->setComponentName(3, "a"), XAO_Exception);
CPPUNIT_ASSERT_THROW(f->getComponentName(3), XAO_Exception);
CPPUNIT_ASSERT_EQUAL(0, f->countSteps());
Step* step = f->addNewStep(0);
CPPUNIT_ASSERT_EQUAL(type, step->getType());
CPPUNIT_ASSERT_EQUAL(1, f->countSteps());
step = f->addNewStep(1);
step = f->addNewStep(2);
CPPUNIT_ASSERT_EQUAL(3, f->countSteps());
CPPUNIT_ASSERT_THROW(f->addNewStep(2), XAO_Exception); // step already exists
CPPUNIT_ASSERT_EQUAL(true, f->removeStep(step));
CPPUNIT_ASSERT_EQUAL(2, f->countSteps());
CPPUNIT_ASSERT_EQUAL(false, f->removeStep(step)); // remove same
CPPUNIT_ASSERT_EQUAL(2, f->countSteps());
return f;
}
void FieldTest::testBooleanField()
{
BooleanField* f = (BooleanField*)testField(XAO::BOOLEAN);
BooleanStep* step = f->getStep(0);
CPPUNIT_ASSERT_EQUAL(XAO::BOOLEAN, step->getType());
CPPUNIT_ASSERT_MESSAGE("step is NULL", step != NULL);
CPPUNIT_ASSERT_THROW(f->getStep(2), XAO_Exception);
step = f->addStep(10);
CPPUNIT_ASSERT_EQUAL(XAO::BOOLEAN, step->getType());
CPPUNIT_ASSERT_EQUAL(3, f->countSteps());
CPPUNIT_ASSERT_THROW(f->addStep(10), XAO_Exception); // step already exists
}
void FieldTest::testIntegerField()
{
IntegerField* f = (IntegerField*)testField(XAO::INTEGER);
IntegerStep* step = f->getStep(0);
CPPUNIT_ASSERT_EQUAL(XAO::INTEGER, step->getType());
CPPUNIT_ASSERT_MESSAGE("step is NULL", step != NULL);
CPPUNIT_ASSERT_THROW(f->getStep(2), XAO_Exception);
step = f->addStep(10);
CPPUNIT_ASSERT_EQUAL(XAO::INTEGER, step->getType());
CPPUNIT_ASSERT_EQUAL(3, f->countSteps());
CPPUNIT_ASSERT_THROW(f->addStep(10), XAO_Exception); // step already exists
}
void FieldTest::testDoubleField()
{
DoubleField* f = (DoubleField*)testField(XAO::DOUBLE);
DoubleStep* step = f->getStep(0);
CPPUNIT_ASSERT_EQUAL(XAO::DOUBLE, step->getType());
CPPUNIT_ASSERT_MESSAGE("step is NULL", step != NULL);
CPPUNIT_ASSERT_THROW(f->getStep(2), XAO_Exception);
step = f->addStep(10);
CPPUNIT_ASSERT_EQUAL(XAO::DOUBLE, step->getType());
CPPUNIT_ASSERT_EQUAL(3, f->countSteps());
CPPUNIT_ASSERT_THROW(f->addStep(10), XAO_Exception); // step already exists
}
void FieldTest::testStringField()
{
StringField* f = (StringField*)testField(XAO::STRING);
StringStep* step = f->getStep(0);
CPPUNIT_ASSERT_EQUAL(XAO::STRING, step->getType());
CPPUNIT_ASSERT_MESSAGE("step is NULL", step != NULL);
CPPUNIT_ASSERT_THROW(f->getStep(2), XAO_Exception);
step = f->addStep(10);
CPPUNIT_ASSERT_EQUAL(XAO::STRING, step->getType());
CPPUNIT_ASSERT_EQUAL(3, f->countSteps());
CPPUNIT_ASSERT_THROW(f->addStep(10), XAO_Exception); // step already exists
}
void FieldTest::testStep(XAO::Type type, Step* step)
{
CPPUNIT_ASSERT_EQUAL(type, step->getType());
CPPUNIT_ASSERT_EQUAL(0, step->getStep());
step->setStep(10);
CPPUNIT_ASSERT_EQUAL(10, step->getStep());
CPPUNIT_ASSERT_EQUAL(0, step->getStamp());
step->setStamp(100);
CPPUNIT_ASSERT_EQUAL(100, step->getStamp());
CPPUNIT_ASSERT_EQUAL(5, step->countElements());
CPPUNIT_ASSERT_EQUAL(3, step->countComponents());
CPPUNIT_ASSERT_EQUAL(15, step->countValues());
}
void FieldTest::testBooleanStep()
{
Step* step = new BooleanStep(0, 0, 5, 3);
testStep(XAO::BOOLEAN, step);
}
void FieldTest::testIntegerStep()
{
Step* step = new IntegerStep(0, 0, 5, 3);
testStep(XAO::INTEGER, step);
}
void FieldTest::testDoubleStep()
{
Step* step = new DoubleStep(0, 0, 5, 3);
testStep(XAO::DOUBLE, step);
}
void FieldTest::testStringStep()
{
Step* step = new StringStep(0, 0, 5, 3);
testStep(XAO::STRING, step);
}
void FieldTest::testBooleanStepValues()
{
int nbComponents = 3; // > 1
int nbElements = 5; // > 1
BooleanStep* step = new BooleanStep(0, 0, nbElements, nbComponents);
for (int i = 0; i < step->countElements(); ++i)
{
for (int j = 0; j < step->countComponents(); ++j)
{
step->setValue(i, j, j % 2 == 0);
}
}
CPPUNIT_ASSERT_EQUAL(true, step->getValue(1, 2));
CPPUNIT_ASSERT_EQUAL(std::string("true"), step->getStringValue(1, 2));
CPPUNIT_ASSERT_THROW(step->getValue(nbElements, 2), XAO_Exception);
CPPUNIT_ASSERT_THROW(step->getValue(1, nbComponents), XAO_Exception);
// get all values
std::vector<bool> values;
values = step->getValues();
CPPUNIT_ASSERT_EQUAL(nbElements*nbComponents, (int)values.size());
for (int i = 0; i < nbElements; ++i)
{
for (int j = 0; j < nbComponents; ++j)
CPPUNIT_ASSERT((j % 2 == 0) == values[i*nbComponents+j]);
}
// get one element
values = step->getElement(2);
CPPUNIT_ASSERT_THROW(step->getElement(nbElements), XAO_Exception);
CPPUNIT_ASSERT_EQUAL(nbComponents, (int)values.size());
for (int i = 0; i < nbComponents; ++i)
CPPUNIT_ASSERT((i % 2 == 0) == values[i]);
// get one component
values = step->getComponent(1);
CPPUNIT_ASSERT_THROW(step->getComponent(nbComponents), XAO_Exception);
CPPUNIT_ASSERT_EQUAL(nbElements, (int)values.size());
for (int i = 0; i < nbElements; ++i)
CPPUNIT_ASSERT(false == values[i]);
// set one element
std::vector<bool> newEltValues;
// only one value
newEltValues.push_back(true);
CPPUNIT_ASSERT_THROW(step->setElement(2, newEltValues), XAO_Exception);
// all values
for (int i = 1; i < nbComponents; ++i)
newEltValues.push_back(true);
step->setElement(2, newEltValues);
// set one component
std::vector<bool> newCompValues;
// only one value
newCompValues.push_back(true);
CPPUNIT_ASSERT_THROW(step->setComponent(1, newCompValues), XAO_Exception);
// all values
for (int i = 1; i < nbElements; ++i)
newCompValues.push_back(true);
step->setComponent(1, newCompValues);
// set string value
step->setStringValue(0, 0, "true");
CPPUNIT_ASSERT_THROW(step->setStringValue(0, 0, "aa"), XAO_Exception);
// set all values
std::vector<bool> allValues;
// only one value
allValues.push_back(true);
CPPUNIT_ASSERT_THROW(step->setValues(allValues), XAO_Exception);
// all values
for (int i = 1; i < nbElements*nbComponents; ++i)
allValues.push_back(true);
step->setValues(allValues);
}
void FieldTest::testIntegerStepValues()
{
int nbComponents = 3;
int nbElements = 5;
IntegerStep* step = new IntegerStep(0, 0, nbElements, nbComponents);
for (int i = 0; i < step->countElements(); ++i)
{
for (int j = 0; j < step->countComponents(); ++j)
step->setValue(i, j, i*10 + j);
}
CPPUNIT_ASSERT_EQUAL(12, step->getValue(1, 2));
CPPUNIT_ASSERT_THROW(step->getValue(nbElements, 2), XAO_Exception);
CPPUNIT_ASSERT_THROW(step->getValue(1, nbComponents), XAO_Exception);
// get all values
std::vector<int> values;
values = step->getValues();
CPPUNIT_ASSERT_EQUAL(nbElements*nbComponents, (int)values.size());
for (int i = 0; i < nbElements; ++i)
{
for (int j = 0; j < nbComponents; ++j)
CPPUNIT_ASSERT_EQUAL(10*i+j, values[i*nbComponents+j]);
}
// get one element
values = step->getElement(2);
CPPUNIT_ASSERT_THROW(step->getElement(nbElements), XAO_Exception);
CPPUNIT_ASSERT_EQUAL(nbComponents, (int)values.size());
for (int i = 0; i < nbComponents; ++i)
CPPUNIT_ASSERT_EQUAL(20+i, values[i]);
// get one component
values = step->getComponent(1);
CPPUNIT_ASSERT_THROW(step->getComponent(nbComponents), XAO_Exception);
CPPUNIT_ASSERT_EQUAL(nbElements, (int)values.size());
for (int i = 0; i < nbElements; ++i)
CPPUNIT_ASSERT_EQUAL(10*i+1, values[i]);
// set one element
std::vector<int> newEltValues;
newEltValues.push_back(1);
CPPUNIT_ASSERT_THROW(step->setElement(2, newEltValues), XAO_Exception);
for (int i = 1; i < nbComponents; ++i)
newEltValues.push_back(1);
step->setElement(2, newEltValues);
// set one component
std::vector<int> newCompValues;
newCompValues.push_back(100);
CPPUNIT_ASSERT_THROW(step->setComponent(1, newCompValues), XAO_Exception);
for (int i = 1; i < nbElements; ++i)
newCompValues.push_back(100);
step->setComponent(1, newCompValues);
// set string value
step->setStringValue(0, 0, "0");
CPPUNIT_ASSERT_THROW(step->setStringValue(0, 0, "aa"), XAO_Exception);
// set all values
std::vector<int> allValues;
// only one value
allValues.push_back(11);
CPPUNIT_ASSERT_THROW(step->setValues(allValues), XAO_Exception);
// all values
for (int i = 1; i < nbElements*nbComponents; ++i)
allValues.push_back(11);
step->setValues(allValues);
}
void FieldTest::testDoubleStepValues()
{
int nbComponents = 3;
int nbElements = 5;
DoubleStep* step = new DoubleStep(0, 0, nbElements, nbComponents);
for (int i = 0; i < step->countElements(); ++i)
{
for (int j = 0; j < step->countComponents(); ++j)
step->setValue(i, j, i*10 + j*0.1);
}
CPPUNIT_ASSERT_EQUAL(10.2, step->getValue(1, 2));
CPPUNIT_ASSERT_THROW(step->getValue(nbElements, 2), XAO_Exception);
CPPUNIT_ASSERT_THROW(step->getValue(1, nbComponents), XAO_Exception);
// get all values
std::vector<double> values;
values = step->getValues();
CPPUNIT_ASSERT_EQUAL(nbElements*nbComponents, (int)values.size());
for (int i = 0; i < nbElements; ++i)
{
for (int j = 0; j < nbComponents; ++j)
CPPUNIT_ASSERT_EQUAL(10*i+j*0.1, values[i*nbComponents+j]);
}
// get one element
values = step->getElement(2);
CPPUNIT_ASSERT_THROW(step->getElement(nbElements), XAO_Exception);
CPPUNIT_ASSERT_EQUAL(nbComponents, (int)values.size());
for (int i = 0; i < nbComponents; ++i)
CPPUNIT_ASSERT_EQUAL(20+i*0.1, values[i]);
// get one component
values = step->getComponent(1);
CPPUNIT_ASSERT_THROW(step->getComponent(nbComponents), XAO_Exception);
CPPUNIT_ASSERT_EQUAL(nbElements, (int)values.size());
for (int i = 0; i < nbElements; ++i)
CPPUNIT_ASSERT_EQUAL(10*i+0.1, values[i]);
// set one element
std::vector<double> newEltValues;
newEltValues.push_back(1.);
CPPUNIT_ASSERT_THROW(step->setElement(2, newEltValues), XAO_Exception);
for (int i = 1; i < nbComponents; ++i)
newEltValues.push_back(1.);
step->setElement(2, newEltValues);
// set one component
std::vector<double> newCompValues;
newCompValues.push_back(100.0);
CPPUNIT_ASSERT_THROW(step->setComponent(1, newCompValues), XAO_Exception);
for (int i = 1; i < nbElements; ++i)
newCompValues.push_back(100.0);
step->setComponent(1, newCompValues);
// set string value
step->setStringValue(0, 0, "0.2");
CPPUNIT_ASSERT_THROW(step->setStringValue(0, 0, "aa"), XAO_Exception);
std::vector<double> allValues;
// only one value
allValues.push_back(1.1);
CPPUNIT_ASSERT_THROW(step->setValues(allValues), XAO_Exception);
// all values
for (int i = 1; i < nbElements*nbComponents; ++i)
allValues.push_back(1.1);
step->setValues(allValues);}
void FieldTest::testStringStepValues()
{
int nbComponents = 3;
int nbElements = 5;
StringStep* step = new StringStep(0, 0, nbElements, nbComponents);
for (int i = 0; i < step->countElements(); ++i)
{
for (int j = 0; j < step->countComponents(); ++j)
step->setValue(i, j, XaoUtils::intToString(i*10 + j));
}
CPPUNIT_ASSERT_EQUAL(std::string("12"), step->getValue(1, 2));
CPPUNIT_ASSERT_THROW(step->getValue(nbElements, 2), XAO_Exception);
CPPUNIT_ASSERT_THROW(step->getValue(1, nbComponents), XAO_Exception);
// get all values
std::vector<std::string> values;
values = step->getValues();
CPPUNIT_ASSERT_EQUAL(nbElements*nbComponents, (int)values.size());
for (int i = 0; i < nbElements; ++i)
{
for (int j = 0; j < nbComponents; ++j)
CPPUNIT_ASSERT_EQUAL(XaoUtils::intToString(10*i+j), values[i*nbComponents+j]);
}
// get one element
values = step->getElement(2);
CPPUNIT_ASSERT_THROW(step->getElement(nbElements), XAO_Exception);
CPPUNIT_ASSERT_EQUAL(nbComponents, (int)values.size());
for (int i = 0; i < nbComponents; ++i)
CPPUNIT_ASSERT_EQUAL(XaoUtils::intToString(20+i), values[i]);
// get one component
values = step->getComponent(1);
CPPUNIT_ASSERT_THROW(step->getComponent(nbComponents), XAO_Exception);
CPPUNIT_ASSERT_EQUAL(nbElements, (int)values.size());
for (int i = 0; i < nbElements; ++i)
CPPUNIT_ASSERT_EQUAL(XaoUtils::intToString(10*i+1), values[i]);
// set one element
std::vector<std::string> newEltValues;
newEltValues.push_back("1");
CPPUNIT_ASSERT_THROW(step->setElement(2, newEltValues), XAO_Exception);
for (int i = 1; i < nbComponents; ++i)
newEltValues.push_back("1");
step->setElement(2, newEltValues);
// set one component
std::vector<std::string> newCompValues;
newCompValues.push_back("100");
CPPUNIT_ASSERT_THROW(step->setComponent(1, newCompValues), XAO_Exception);
for (int i = 1; i < nbElements; ++i)
newCompValues.push_back("100");
step->setComponent(1, newCompValues);
// set string value
step->setStringValue(0, 0, "0");
std::vector<std::string> allValues;
// only one value
allValues.push_back("abc");
CPPUNIT_ASSERT_THROW(step->setValues(allValues), XAO_Exception);
// all values
for (int i = 1; i < nbElements*nbComponents; ++i)
allValues.push_back("abc");
step->setValues(allValues);
}
void FieldTest::testSetComponents()
{
// field with 3 components
Field* f = Field::createField(XAO::INTEGER, XAO::FACE, 6, 3);
CPPUNIT_ASSERT_EQUAL(std::string(""), f->getComponentName(0));
CPPUNIT_ASSERT_EQUAL(std::string(""), f->getComponentName(1));
CPPUNIT_ASSERT_EQUAL(std::string(""), f->getComponentName(2));
std::vector<std::string> names;
names.push_back("vx");
f->setComponentsNames(names);
CPPUNIT_ASSERT_EQUAL(std::string("vx"), f->getComponentName(0));
CPPUNIT_ASSERT_EQUAL(std::string(""), f->getComponentName(1));
CPPUNIT_ASSERT_EQUAL(std::string(""), f->getComponentName(2));
names.push_back("vy");
f->setComponentsNames(names);
CPPUNIT_ASSERT_EQUAL(std::string("vx"), f->getComponentName(0));
CPPUNIT_ASSERT_EQUAL(std::string("vy"), f->getComponentName(1));
CPPUNIT_ASSERT_EQUAL(std::string(""), f->getComponentName(2));
names.push_back("vz");
names.push_back("t");
f->setComponentsNames(names);
CPPUNIT_ASSERT_EQUAL(std::string("vx"), f->getComponentName(0));
CPPUNIT_ASSERT_EQUAL(std::string("vy"), f->getComponentName(1));
CPPUNIT_ASSERT_EQUAL(std::string("vz"), f->getComponentName(2));
}

View File

@ -0,0 +1,55 @@
#ifndef __XAO_FIELD_TEST_HXX__
#define __XAO_FIELD_TEST_HXX__
#include <cppunit/extensions/HelperMacros.h>
#include "../XAO_Xao.hxx"
#include "../XAO_Field.hxx"
#include "../XAO_Step.hxx"
namespace XAO
{
class FieldTest: public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(FieldTest);
CPPUNIT_TEST(testBooleanField);
CPPUNIT_TEST(testDoubleField);
CPPUNIT_TEST(testIntegerField);
CPPUNIT_TEST(testStringField);
CPPUNIT_TEST(testBooleanStep);
CPPUNIT_TEST(testIntegerStep);
CPPUNIT_TEST(testDoubleStep);
CPPUNIT_TEST(testStringStep);
CPPUNIT_TEST(testBooleanStepValues);
CPPUNIT_TEST(testIntegerStepValues);
CPPUNIT_TEST(testDoubleStepValues);
CPPUNIT_TEST(testStringStepValues);
CPPUNIT_TEST(testSetComponents);
CPPUNIT_TEST_SUITE_END();
public:
void setUp();
void tearDown();
void cleanUp();
Field* testField(XAO::Type type);
void testBooleanField();
void testIntegerField();
void testDoubleField();
void testStringField();
void testStep(XAO::Type type, Step* step);
void testBooleanStep();
void testIntegerStep();
void testDoubleStep();
void testStringStep();
void testBooleanStepValues();
void testIntegerStepValues();
void testDoubleStepValues();
void testStringStepValues();
void testSetComponents();
};
}
#endif // __XAO_FIELD_TEST_HXX__

View File

@ -0,0 +1,142 @@
#include <vector>
#include "TestUtils.hxx"
#include "GeometryTest.hxx"
#include "../XAO_XaoUtils.hxx"
#include "../XAO_Geometry.hxx"
#include "../XAO_GeometricElement.hxx"
using namespace XAO;
void GeometryTest::setUp()
{
}
void GeometryTest::tearDown()
{
}
void GeometryTest::cleanUp()
{
}
void GeometryTest::testGeometryElement()
{
GeometricElement elt;
CPPUNIT_ASSERT_EQUAL(false, elt.hasName());
CPPUNIT_ASSERT_EQUAL(std::string(""), elt.getName());
CPPUNIT_ASSERT_EQUAL(std::string(""), elt.getReference());
elt.setName("test");
CPPUNIT_ASSERT_EQUAL(true, elt.hasName());
CPPUNIT_ASSERT_EQUAL(std::string("test"), elt.getName());
elt.setReference("abc");
CPPUNIT_ASSERT_EQUAL(std::string("abc"), elt.getReference());
GeometricElement elt2("aa", "bb");
CPPUNIT_ASSERT_EQUAL(std::string("aa"), elt2.getName());
CPPUNIT_ASSERT_EQUAL(std::string("bb"), elt2.getReference());
}
void GeometryTest::testGeometryElementList()
{
GeometricElementList lst;
CPPUNIT_ASSERT_EQUAL(0, lst.getSize());
lst.setSize(10);
CPPUNIT_ASSERT_EQUAL(10, lst.getSize());
GeometricElementList otherLst(15);
CPPUNIT_ASSERT_EQUAL(15, otherLst.getSize());
CPPUNIT_ASSERT_EQUAL(std::string(""), otherLst.getName(0));
CPPUNIT_ASSERT_EQUAL(std::string(""), otherLst.getReference(0));
CPPUNIT_ASSERT_THROW(otherLst.getName(20), XAO_Exception);
CPPUNIT_ASSERT_THROW(otherLst.getReference(20), XAO_Exception);
CPPUNIT_ASSERT_THROW(otherLst.hasName(20), XAO_Exception);
otherLst.setName(0, "aa");
CPPUNIT_ASSERT_EQUAL(std::string("aa"), otherLst.getName(0));
CPPUNIT_ASSERT_THROW(otherLst.setName(20, "aa"), XAO_Exception);
otherLst.setReference(0, "bb");
CPPUNIT_ASSERT_EQUAL(std::string("bb"), otherLst.getReference(0));
CPPUNIT_ASSERT_THROW(otherLst.setReference(20, "aa"), XAO_Exception);
otherLst.setSize(10);
CPPUNIT_ASSERT_EQUAL(std::string(""), otherLst.getName(0));
CPPUNIT_ASSERT_EQUAL(std::string(""), otherLst.getReference(0));
CPPUNIT_ASSERT_EQUAL(false, otherLst.hasName(0));
otherLst.setElement(3, "name", "ref");
CPPUNIT_ASSERT_EQUAL(std::string("name"), otherLst.getName(3));
CPPUNIT_ASSERT_EQUAL(std::string("ref"), otherLst.getReference(3));
CPPUNIT_ASSERT_EQUAL(true, otherLst.hasName(3));
CPPUNIT_ASSERT_THROW(otherLst.setElement(30, "name", "ref"), XAO_Exception);
// ---- create elements "name i", "Ri"
for (int i = 0; i < otherLst.getSize(); ++i)
{
std::ostringstream name;
name << "name " << i;
std::ostringstream ref;
ref << "R" << i;
otherLst.setElement(i, name.str(), ref.str());
}
CPPUNIT_ASSERT_EQUAL(8, otherLst.getIndexByReference("R8"));
CPPUNIT_ASSERT_THROW(otherLst.getIndexByReference("ZZ"), XAO_Exception);
GeometricElementList::iterator first = otherLst.begin();
GeometricElement firstElt = first->second;
CPPUNIT_ASSERT_EQUAL(std::string("R0"), firstElt.getReference());
}
void GeometryTest::testGeometry()
{
Geometry* geom = Geometry::createGeometry(XAO::BREP, "cube");
CPPUNIT_ASSERT_EQUAL(std::string("cube"), geom->getName());
CPPUNIT_ASSERT_EQUAL(XAO::BREP, geom->getFormat());
geom->setName("sphere");
CPPUNIT_ASSERT_EQUAL(std::string("sphere"), geom->getName());
delete geom;
}
void GeometryTest::testGeometryErrors()
{
CPPUNIT_ASSERT_THROW(Geometry::createGeometry(XAO::STEP), XAO_Exception);
}
void GeometryTest::testSetElement()
{
Geometry* geom = Geometry::createGeometry(XAO::BREP, "cube");
CPPUNIT_ASSERT_THROW(geom->setVertexName(0, "aa"), XAO_Exception);
char* txt = TestUtils::readTextFile(TestUtils::getTestFilePath("Box_1.brep"));
geom->setShapeString(txt);
CPPUNIT_ASSERT_EQUAL(false, geom->hasVertexName(0));
geom->setVertexName(0, "va");
CPPUNIT_ASSERT_EQUAL(true, geom->hasVertexName(0));
CPPUNIT_ASSERT_EQUAL(std::string("va"), geom->getVertexName(0));
CPPUNIT_ASSERT_THROW(geom->getVertexName(100), XAO_Exception);
CPPUNIT_ASSERT_THROW(geom->hasVertexName(100), XAO_Exception);
geom->setEdgeName(0, "ea");
CPPUNIT_ASSERT_EQUAL(std::string("ea"), geom->getEdgeName(0));
CPPUNIT_ASSERT_THROW(geom->getEdgeName(100), XAO_Exception);
geom->setFaceName(0, "fa");
CPPUNIT_ASSERT_EQUAL(std::string("fa"), geom->getFaceName(0));
CPPUNIT_ASSERT_THROW(geom->getFaceName(100), XAO_Exception);
geom->setSolidName(0, "sa");
CPPUNIT_ASSERT_EQUAL(std::string("sa"), geom->getSolidName(0));
CPPUNIT_ASSERT_THROW(geom->getSolidName(100), XAO_Exception);
delete geom;
}

View File

@ -0,0 +1,30 @@
#ifndef __XAO_GEOMETRY_TEST_HXX__
#define __XAO_GEOMETRY_TEST_HXX__
#include <cppunit/extensions/HelperMacros.h>
namespace XAO
{
class GeometryTest: public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(GeometryTest);
CPPUNIT_TEST(testGeometryElement);
CPPUNIT_TEST(testGeometryElementList);
CPPUNIT_TEST(testGeometry);
CPPUNIT_TEST(testGeometryErrors);
CPPUNIT_TEST_SUITE_END();
public:
void setUp();
void tearDown();
void cleanUp();
void testGeometryElement();
void testGeometryElementList();
void testGeometry();
void testGeometryErrors();
void testSetElement();
};
}
#endif // __XAO_GEOMETRY_TEST_HXX__

View File

@ -0,0 +1,58 @@
#include <vector>
#include "TestUtils.hxx"
#include "GroupTest.hxx"
#include "../XAO_XaoUtils.hxx"
#include "../XAO_Xao.hxx"
#include "../XAO_Group.hxx"
using namespace XAO;
void GroupTest::setUp()
{
}
void GroupTest::tearDown()
{
}
void GroupTest::cleanUp()
{
}
void GroupTest::testGroup()
{
Group* group = new Group(XAO::FACE, 20);
CPPUNIT_ASSERT_EQUAL(XAO::FACE, group->getDimension());
CPPUNIT_ASSERT_EQUAL(20, group->getNbElements());
CPPUNIT_ASSERT_EQUAL(std::string(""), group->getName());
group->setName("the Group");
CPPUNIT_ASSERT_EQUAL(std::string("the Group"), group->getName());
CPPUNIT_ASSERT_EQUAL(0, group->count());
group->add(10);
CPPUNIT_ASSERT_EQUAL(1, group->count());
group->add(12);
CPPUNIT_ASSERT_EQUAL(2, group->count());
group->add(12);
CPPUNIT_ASSERT_EQUAL(2, group->count());
CPPUNIT_ASSERT_EQUAL(10, group->get(0));
CPPUNIT_ASSERT_EQUAL(12, group->get(1));
CPPUNIT_ASSERT_THROW(group->get(2), XAO_Exception);
group->remove(15);
CPPUNIT_ASSERT_EQUAL(2, group->count());
group->remove(10);
CPPUNIT_ASSERT_EQUAL(1, group->count());
CPPUNIT_ASSERT_EQUAL(12, group->get(0));
delete group;
}
void GroupTest::testGroupErrors()
{
CPPUNIT_ASSERT_THROW(new Group(XAO::WHOLE, 20), XAO_Exception);
}

View File

@ -0,0 +1,25 @@
#ifndef __XAO_GROUP_TEST_HXX__
#define __XAO_GROUP_TEST_HXX__
#include <cppunit/extensions/HelperMacros.h>
namespace XAO
{
class GroupTest: public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(GroupTest);
CPPUNIT_TEST(testGroup);
CPPUNIT_TEST(testGroupErrors);
CPPUNIT_TEST_SUITE_END();
public:
void setUp();
void tearDown();
void cleanUp();
void testGroup();
void testGroupErrors();
};
}
#endif // __XAO_GROUP_TEST_HXX__

View File

@ -0,0 +1,187 @@
// 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 "TestUtils.hxx"
#include "ImportExportTest.hxx"
#include "../XAO_XaoUtils.hxx"
#include "../XAO_Geometry.hxx"
#include "../XAO_Group.hxx"
#include "../XAO_Field.hxx"
#include "../XAO_IntegerField.hxx"
#include "../XAO_IntegerStep.hxx"
using namespace XAO;
void ImportExportTest::setUp()
{
}
void ImportExportTest::tearDown()
{
}
void ImportExportTest::cleanUp()
{
}
void ImportExportTest::testExportNoGeometry()
{
Xao xao("me", "1.0");
bool res = xao.exportXAO("empty.xao");
CPPUNIT_ASSERT(res);
}
void ImportExportTest::testExportGeometry()
{
Xao xao("me", "1.0");
Geometry* geom = Geometry::createGeometry(XAO::BREP);
geom->setName("mygeom");
CPPUNIT_ASSERT_EQUAL(false, geom->isReadOnly());
// add elements
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");
xao.setGeometry(geom);
CPPUNIT_ASSERT_EQUAL(true, geom->isReadOnly());
// groups
Group* group = xao.addGroup(XAO::SOLID);
group->setName("boite1");
group->add(0);
group = xao.addGroup(XAO::FACE);
group->setName("faces");
group->add(0);
group->add(1);
// fields
IntegerField* field = (IntegerField*)xao.addField(XAO::INTEGER, XAO::FACE, 2, "color");
for (int stepIndex = 0; stepIndex < 10; ++stepIndex)
{
IntegerStep* istep = field->addStep(stepIndex, 100*stepIndex);
for (int eltIndex = 0; eltIndex < istep->countElements(); ++eltIndex)
{
for (int compIndex = 0; compIndex < istep->countComponents(); ++compIndex)
{
istep->setValue(eltIndex, compIndex, istep->getStamp() + eltIndex*10 + compIndex);
}
}
}
bool res = xao.exportXAO("mygeom.xao");
CPPUNIT_ASSERT(res);
std::string xml = xao.getXML();
//CPPUNIT_ASSERT_EQUAL(strlen(xml) == 1007);
}
void ImportExportTest::testGeometryError()
{
Geometry* geom = Geometry::createGeometry(XAO::BREP);
geom->setName("mygeom");
geom->setCountVertices(2);
CPPUNIT_ASSERT_THROW(geom->setVertex(3, "v4", "4"), XAO_Exception);
delete geom;
}
void ImportExportTest::testImportXao()
{
Xao xao;
xao.importXAO(TestUtils::getTestFilePath("test.xao"));
checkImport(xao);
}
void ImportExportTest::testImportXaoFromText()
{
char* txt = TestUtils::readTextFile(TestUtils::getTestFilePath("test.xao"));
Xao xao;
xao.setXML(txt);
checkImport(xao);
}
void ImportExportTest::checkImport(Xao& xao)
{
CPPUNIT_ASSERT_EQUAL(std::string("me"), xao.getAuthor());
CPPUNIT_ASSERT_EQUAL(std::string("1.0"), xao.getVersion());
Geometry* geom = xao.getGeometry();
CPPUNIT_ASSERT(geom != NULL);
CPPUNIT_ASSERT_EQUAL(std::string("mygeom"), geom->getName());
CPPUNIT_ASSERT_EQUAL(4, geom->countVertices());
CPPUNIT_ASSERT_EQUAL(std::string("v1"), geom->getVertexName(0));
CPPUNIT_ASSERT_EQUAL(std::string("1"), geom->getVertexReference(0));
CPPUNIT_ASSERT_EQUAL(std::string(""), geom->getVertexName(1));
CPPUNIT_ASSERT_EQUAL(std::string("2"), geom->getVertexReference(1));
CPPUNIT_ASSERT_EQUAL(std::string("v3"), geom->getVertexName(2));
CPPUNIT_ASSERT_EQUAL(std::string("3"), geom->getVertexReference(2));
CPPUNIT_ASSERT_EQUAL(std::string(""), geom->getVertexName(3));
CPPUNIT_ASSERT_EQUAL(std::string("4"), geom->getVertexReference(3));
CPPUNIT_ASSERT_EQUAL(3, geom->countEdges());
CPPUNIT_ASSERT_EQUAL(std::string("e1"), geom->getEdgeName(0));
CPPUNIT_ASSERT_EQUAL(std::string("5"), geom->getEdgeReference(0));
CPPUNIT_ASSERT_EQUAL(std::string(""), geom->getEdgeName(1));
CPPUNIT_ASSERT_EQUAL(std::string("6"), geom->getEdgeReference(1));
CPPUNIT_ASSERT_EQUAL(std::string("e3"), geom->getEdgeName(2));
CPPUNIT_ASSERT_EQUAL(std::string("7"), geom->getEdgeReference(2));
CPPUNIT_ASSERT_EQUAL(2, geom->countFaces());
CPPUNIT_ASSERT_EQUAL(std::string("f1"), geom->getFaceName(0));
CPPUNIT_ASSERT_EQUAL(std::string("8"), geom->getFaceReference(0));
CPPUNIT_ASSERT_EQUAL(std::string(""), geom->getFaceName(1));
CPPUNIT_ASSERT_EQUAL(std::string("9"), geom->getFaceReference(1));
CPPUNIT_ASSERT_EQUAL(1, geom->countSolids());
CPPUNIT_ASSERT_EQUAL(std::string("s1"), geom->getSolidName(0));
CPPUNIT_ASSERT_EQUAL(std::string("10"), geom->getSolidReference(0));
CPPUNIT_ASSERT_EQUAL(2, xao.countGroups());
Group* group = xao.getGroup(0);
CPPUNIT_ASSERT_EQUAL(1, group->count());
CPPUNIT_ASSERT_EQUAL(std::string("boite_1"), group->getName());
CPPUNIT_ASSERT_EQUAL(XAO::SOLID, group->getDimension());
CPPUNIT_ASSERT_EQUAL(0, group->get(0));
group = xao.getGroup(1);
CPPUNIT_ASSERT_EQUAL(2, group->count());
CPPUNIT_ASSERT_EQUAL(std::string(""), group->getName());
CPPUNIT_ASSERT_EQUAL(XAO::FACE, group->getDimension());
CPPUNIT_ASSERT_EQUAL(0, group->get(0));
CPPUNIT_ASSERT_EQUAL(1, group->get(1));
}

View File

@ -0,0 +1,35 @@
#ifndef __XAO_IMPORT_TEST_HXX__
#define __XAO_IMPORT_TEST_HXX__
#include <cppunit/extensions/HelperMacros.h>
#include "../XAO_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(testImportXaoFromText);
CPPUNIT_TEST_SUITE_END();
public:
void setUp();
void tearDown();
void cleanUp();
void testExportNoGeometry();
void testExportGeometry();
void testGeometryError();
void testImportXao();
void testImportXaoFromText();
void checkImport(Xao& xao);
};
}
#endif // __XAO_IMPORT_TEST_HXX__

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;
}
else 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

View File

@ -0,0 +1,36 @@
#ifndef __XAO_TESTUTILS_HXX__
#define __XAO_TESTUTILS_HXX__
#include <fstream>
#include <cstdlib>
namespace XAO
{
class TestUtils
{
public:
static std::string getTestFilePath(const std::string& fileName)
{
std::string dataDir = getenv("GEOM_SRC_DIR");
dataDir += "/src/XAO/tests/data/" + fileName;
return dataDir;
}
static char* readTextFile(const std::string& filePath)
{
std::ifstream rstr;
int length;
rstr.open(filePath.c_str());
rstr.seekg(0, rstr.end); // go to the end
length = rstr.tellg(); // report location (this is the length)
rstr.seekg(0, rstr.beg); // go back to the beginning
char* txt = new char[length]; // allocate memory for a buffer of appropriate dimension
rstr.read(txt, length); // read the whole file into the buffer
rstr.close();
return txt;
}
};
}
#endif /* __XAO_TESTUTILS_HXX__ */

View File

@ -0,0 +1,17 @@
#include "XaoUtilsTest.hxx"
#include "GroupTest.hxx"
#include "FieldTest.hxx"
#include "GeometryTest.hxx"
#include "ImportExportTest.hxx"
#include "BrepGeometryTest.hxx"
#include "XaoTest.hxx"
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::XaoUtilsTest);
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::GroupTest);
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::FieldTest);
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::GeometryTest);
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::ImportExportTest);
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::BrepGeometryTest);
CPPUNIT_TEST_SUITE_REGISTRATION(XAO::XaoTest);
#include "MainTest.hxx"

103
src/XAO/tests/XaoTest.cxx Normal file
View File

@ -0,0 +1,103 @@
#include <vector>
#include "TestUtils.hxx"
#include "XaoTest.hxx"
#include "../XAO_XaoUtils.hxx"
#include "../XAO_Xao.hxx"
#include "../XAO_BrepGeometry.hxx"
#include "../XAO_Group.hxx"
#include "../XAO_Field.hxx"
using namespace XAO;
void XaoTest::setUp()
{
}
void XaoTest::tearDown()
{
}
void XaoTest::cleanUp()
{
}
void XaoTest::testGroups()
{
Xao obj;
CPPUNIT_ASSERT_THROW(obj.addGroup(XAO::FACE), XAO_Exception);
BrepGeometry* geom = new BrepGeometry("test");
obj.setGeometry(geom);
Group* gr = obj.addGroup(XAO::FACE);
CPPUNIT_ASSERT_EQUAL(XAO::FACE, gr->getDimension());
CPPUNIT_ASSERT_EQUAL(1, obj.countGroups());
Group* gr2 = obj.addGroup(XAO::FACE);
gr2->setName("AA");
Group* agr = obj.getGroup(0);
CPPUNIT_ASSERT(gr == agr);
CPPUNIT_ASSERT_THROW(obj.getGroup(10), XAO_Exception);
CPPUNIT_ASSERT_EQUAL(true, obj.removeGroup(gr2));
CPPUNIT_ASSERT_EQUAL(1, obj.countGroups());
// remove other group
Group* gr3 = new Group(XAO::FACE, 3);
CPPUNIT_ASSERT_EQUAL(false, obj.removeGroup(gr3));
delete gr3;
}
void XaoTest::testFields()
{
Xao obj;
CPPUNIT_ASSERT_THROW(obj.addField(XAO::INTEGER, XAO::FACE, 3), XAO_Exception);
BrepGeometry* geom = new BrepGeometry("test");
obj.setGeometry(geom);
Field* fi = obj.addField(XAO::INTEGER, XAO::FACE, 3);
CPPUNIT_ASSERT_EQUAL(1, obj.countFields());
CPPUNIT_ASSERT_EQUAL(XAO::INTEGER, fi->getType());
CPPUNIT_ASSERT_EQUAL(XAO::FACE, fi->getDimension());
CPPUNIT_ASSERT_EQUAL(3, fi->countComponents());
Field* fb = obj.addField(XAO::BOOLEAN, XAO::FACE, 3);
Field* fd = obj.addField(XAO::DOUBLE, XAO::FACE, 3);
Field* fs = obj.addField(XAO::STRING, XAO::FACE, 3);
CPPUNIT_ASSERT_EQUAL(4, obj.countFields());
CPPUNIT_ASSERT_THROW(obj.getField(10), XAO_Exception);
CPPUNIT_ASSERT_EQUAL(true, obj.removeField(fb));
CPPUNIT_ASSERT_EQUAL(3, obj.countFields());
Field* ff = Field::createField(XAO::INTEGER, XAO::FACE, 3, 3);
CPPUNIT_ASSERT_EQUAL(false, obj.removeField(ff));
delete ff;
}
void XaoTest::testFieldsTypes()
{
Xao obj;
BrepGeometry* geom = new BrepGeometry("test");
obj.setGeometry(geom);
IntegerField* fi = obj.addIntegerField(XAO::FACE, 3);
BooleanField* fb = obj.addBooleanField(XAO::FACE, 3);
DoubleField* fd = obj.addDoubleField(XAO::FACE, 3);
StringField* fs = obj.addStringField(XAO::FACE, 3);
IntegerField* gfi = obj.getIntegerField(0);
CPPUNIT_ASSERT(gfi == fi);
BooleanField* gfb = obj.getBooleanField(1);
CPPUNIT_ASSERT(gfb == fb);
DoubleField* gfd = obj.getDoubleField(2);
CPPUNIT_ASSERT(gfd == fd);
StringField* gfs = obj.getStringField(3);
CPPUNIT_ASSERT(gfs == fs);
CPPUNIT_ASSERT_THROW(obj.getIntegerField(1), XAO_Exception);
CPPUNIT_ASSERT_THROW(obj.getBooleanField(0), XAO_Exception);
CPPUNIT_ASSERT_THROW(obj.getDoubleField(0), XAO_Exception);
CPPUNIT_ASSERT_THROW(obj.getStringField(0), XAO_Exception);
}

27
src/XAO/tests/XaoTest.hxx Normal file
View File

@ -0,0 +1,27 @@
#ifndef __XAO_XAO_TEST_HXX__
#define __XAO_XAO_TEST_HXX__
#include <cppunit/extensions/HelperMacros.h>
namespace XAO
{
class XaoTest: public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(XaoTest);
CPPUNIT_TEST(testGroups);
CPPUNIT_TEST(testFields);
CPPUNIT_TEST(testFieldsTypes);
CPPUNIT_TEST_SUITE_END();
public:
void setUp();
void tearDown();
void cleanUp();
void testGroups();
void testFields();
void testFieldsTypes();
};
}
#endif // __XAO_GROUP_TEST_HXX__

View File

@ -0,0 +1,88 @@
#include "XaoUtilsTest.hxx"
#include "../XAO_Xao.hxx"
#include "../XAO_XaoUtils.hxx"
using namespace XAO;
void XaoUtilsTest::setUp()
{
}
void XaoUtilsTest::tearDown()
{
}
void XaoUtilsTest::cleanUp()
{
}
void XaoUtilsTest::testBoolean()
{
CPPUNIT_ASSERT_EQUAL(std::string("true"), XaoUtils::booleanToString(true));
CPPUNIT_ASSERT_EQUAL(std::string("false"), XaoUtils::booleanToString(false));
CPPUNIT_ASSERT_EQUAL(true, XaoUtils::stringToBoolean("true"));
CPPUNIT_ASSERT_EQUAL(true, XaoUtils::stringToBoolean("1"));
CPPUNIT_ASSERT_EQUAL(false, XaoUtils::stringToBoolean("false"));
CPPUNIT_ASSERT_EQUAL(false, XaoUtils::stringToBoolean("0"));
CPPUNIT_ASSERT_THROW(XaoUtils::stringToBoolean("abc"), XAO_Exception);
}
void XaoUtilsTest::testInteger()
{
CPPUNIT_ASSERT_EQUAL(std::string("0"), XaoUtils::intToString(0));
CPPUNIT_ASSERT_EQUAL(std::string("123"), XaoUtils::intToString(123));
CPPUNIT_ASSERT_EQUAL(123, XaoUtils::stringToInt("123"));
CPPUNIT_ASSERT_THROW(XaoUtils::stringToInt("abc"), XAO_Exception);
}
void XaoUtilsTest::testDouble()
{
CPPUNIT_ASSERT_EQUAL(std::string("0"), XaoUtils::doubleToString(0));
CPPUNIT_ASSERT_EQUAL(std::string("12.3"), XaoUtils::doubleToString(12.3));
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.123, XaoUtils::stringToDouble("0.123"), 1e-3);
CPPUNIT_ASSERT_THROW(XaoUtils::stringToDouble("abc"), XAO_Exception);
}
void XaoUtilsTest::testDimension()
{
CPPUNIT_ASSERT_EQUAL(std::string("vertex"), XaoUtils::dimensionToString(XAO::VERTEX));
CPPUNIT_ASSERT_EQUAL(std::string("edge"), XaoUtils::dimensionToString(XAO::EDGE));
CPPUNIT_ASSERT_EQUAL(std::string("face"), XaoUtils::dimensionToString(XAO::FACE));
CPPUNIT_ASSERT_EQUAL(std::string("solid"), XaoUtils::dimensionToString(XAO::SOLID));
CPPUNIT_ASSERT_EQUAL(std::string("whole"), XaoUtils::dimensionToString(XAO::WHOLE));
CPPUNIT_ASSERT_EQUAL(XAO::VERTEX, XaoUtils::stringToDimension("vertex"));
CPPUNIT_ASSERT_EQUAL(XAO::EDGE, XaoUtils::stringToDimension("edge"));
CPPUNIT_ASSERT_EQUAL(XAO::FACE, XaoUtils::stringToDimension("face"));
CPPUNIT_ASSERT_EQUAL(XAO::SOLID, XaoUtils::stringToDimension("solid"));
CPPUNIT_ASSERT_EQUAL(XAO::WHOLE, XaoUtils::stringToDimension("whole"));
CPPUNIT_ASSERT_THROW(XaoUtils::stringToDimension("zz"), XAO_Exception);
}
void XaoUtilsTest::testType()
{
CPPUNIT_ASSERT_EQUAL(std::string("boolean"), XaoUtils::fieldTypeToString(XAO::BOOLEAN));
CPPUNIT_ASSERT_EQUAL(std::string("integer"), XaoUtils::fieldTypeToString(XAO::INTEGER));
CPPUNIT_ASSERT_EQUAL(std::string("double"), XaoUtils::fieldTypeToString(XAO::DOUBLE));
CPPUNIT_ASSERT_EQUAL(std::string("string"), XaoUtils::fieldTypeToString(XAO::STRING));
CPPUNIT_ASSERT_EQUAL(XAO::BOOLEAN, XaoUtils::stringToFieldType("boolean"));
CPPUNIT_ASSERT_EQUAL(XAO::INTEGER, XaoUtils::stringToFieldType("integer"));
CPPUNIT_ASSERT_EQUAL(XAO::DOUBLE, XaoUtils::stringToFieldType("double"));
CPPUNIT_ASSERT_EQUAL(XAO::STRING, XaoUtils::stringToFieldType("string"));
CPPUNIT_ASSERT_THROW(XaoUtils::stringToFieldType("zz"), XAO_Exception);
}
void XaoUtilsTest::testFormat()
{
CPPUNIT_ASSERT_EQUAL(std::string("BREP"), XaoUtils::shapeFormatToString(XAO::BREP));
CPPUNIT_ASSERT_EQUAL(std::string("STEP"), XaoUtils::shapeFormatToString(XAO::STEP));
CPPUNIT_ASSERT_EQUAL(XAO::BREP, XaoUtils::stringToShapeFormat("BREP"));
CPPUNIT_ASSERT_EQUAL(XAO::STEP, XaoUtils::stringToShapeFormat("STEP"));
CPPUNIT_ASSERT_THROW(XaoUtils::stringToShapeFormat("zz"), XAO_Exception);
}

View File

@ -0,0 +1,33 @@
#ifndef __XAO_UTILS_TEST_HXX__
#define __XAO_UTILS_TEST_HXX__
#include <cppunit/extensions/HelperMacros.h>
namespace XAO
{
class XaoUtilsTest: public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(XaoUtilsTest);
CPPUNIT_TEST(testBoolean);
CPPUNIT_TEST(testInteger);
CPPUNIT_TEST(testDouble);
CPPUNIT_TEST(testDimension);
CPPUNIT_TEST(testType);
CPPUNIT_TEST(testFormat);
CPPUNIT_TEST_SUITE_END();
public:
void setUp();
void tearDown();
void cleanUp();
void testBoolean();
void testInteger();
void testDouble();
void testDimension();
void testType();
void testFormat();
};
}
#endif // __XAO_FIELD_TEST_HXX__

Some files were not shown because too many files have changed in this diff Show More