#include <ModelHighAPI_Services.h>
#include <ModelHighAPI_Tools.h>
-std::list<double> getBasicProperties(const std::shared_ptr<ModelAPI_Document>& thePart,
- const ModelHighAPI_Selection& theObject)
+//=================================================================================================
+std::list<double> getBasicProperties(const std::shared_ptr<ModelAPI_Document>& thePart,
+ const ModelHighAPI_Selection& theObject)
{
FeaturePtr aPointCoodFeat = thePart->addFeature(FeaturesPlugin_GeometryCalculation::ID());
AttributeDoubleArrayPtr aResult = std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(
aPointCoodFeat->attribute(FeaturesPlugin_GeometryCalculation::RESULT_VALUES_ID()));
- for ( int i : {0, 1, 2})
+ for (int i : {0, 1, 2})
res.push_back( aResult->value(i));
return res;
/// \ingroup CPPHighAPI
/// \brief get the basic properties (lenght, Surface area, volume)
FEATURESAPI_EXPORT
-std::list<double> getBasicProperties(const std::shared_ptr<ModelAPI_Document>& thePart,
- const ModelHighAPI_Selection& theObject);
+std::list<double> getBasicProperties(const std::shared_ptr<ModelAPI_Document>& thePart,
+ const ModelHighAPI_Selection& theObject);
#endif // FeaturesAPI_GeometryCalculation_H_
\ No newline at end of file
# additional include directories
INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/GeomDataAPI
${PROJECT_SOURCE_DIR}/src/Locale
- ${PROJECT_SOURCE_DIR}/src/PrimitivesPlugin
${QT_INCLUDES})
# additional preprocessor / compiler flags
fillet_widget.xml
fillet1d_widget.xml
measurement_widget.xml
- GeometryCalculation_widget.xml
+ geometry_calculation_widget.xml
fusion_faces_widget.xml
chamfer_widget.xml
copy_widget.xml
#include <Config_PropManager.h>
#include <GeomAPI_Shape.h>
-#include <GeomAPI_Pnt.h>
-#include <GeomAPI_Vertex.h>
#include <GeomAlgoAPI_BasicProperties.h>
#include <iomanip>
#include <sstream>
+//=================================================================================================
FeaturesPlugin_GeometryCalculation::FeaturesPlugin_GeometryCalculation()
{
}
+//=================================================================================================
void FeaturesPlugin_GeometryCalculation::initAttributes()
{
// attribute for point selected
data()->addAttribute(VOLUME_ID(), ModelAPI_AttributeString::typeId());
data()->addAttribute(RESULT_VALUES_ID(), ModelAPI_AttributeDoubleArray::typeId());
-
data()->realArray(RESULT_VALUES_ID())->setSize(3);
}
+//=================================================================================================
void FeaturesPlugin_GeometryCalculation::execute()
{
}
+//=================================================================================================
void FeaturesPlugin_GeometryCalculation::attributeChanged(const std::string& theID)
{
if (theID == OBJECT_SELECTED_ID()) {
if (!aShape && aSelection->context())
aShape = aSelection->context()->shape();
}
- if (aShape){
+ if (aShape) {
double aTolerance = 0.0001;
double aLength;
double aSurfArea;
double aVolume;
std::string aError;
- if( !GetBasicProperties( aShape,
+ if (!GetBasicProperties(aShape,
aTolerance,
aLength,
aSurfArea,
aVolume,
- aError) )
+ aError))
setError("Error in Geometry calculation :" + aError);
streamL << std::setprecision(14) << aLength;
aValues->setValue(2, aVolume);
}
- string(LENGHT_ID() )->setValue( "Lenght = " + streamL.str() );
- string(AREA_ID() )->setValue( "Area = " + streamA.str() );
- string(VOLUME_ID() )->setValue( "Volume = " + streamV.str() );
+ string(LENGHT_ID())->setValue("Lenght = " + streamL.str());
+ string(AREA_ID())->setValue("Area = " + streamA.str());
+ string(VOLUME_ID())->setValue("Volume = " + streamV.str());
}
}
class FeaturesPlugin_GeometryCalculation : public ModelAPI_Feature
{
public:
- inline static const std::string& ID()
+ inline static const std::string& ID()
{
static const std::string MY_ID("GeometryCalculation");
return MY_ID;
return MY_VOLUME_ID;
}
- /// Attribute name for values of result.
+ /// Attribute name for values of result.
inline static const std::string& RESULT_VALUES_ID()
{
static const std::string MY_RESULT_VALUES_ID("result_values");
+++ /dev/null
-<source>
- <shape_selector id="main_object"
- label="Object"
- tooltip="Select a object"
- shape_types="edges faces solids compsolids objects"
- default=""
- geometrical_selection="true">
- <validator id="GeomValidators_ShapeType" parameters="line,edge,wire,face,shell,solid,compsolid,compound"/>
- </shape_selector>
- <label id="lenght" isSelectable = "true"/>
- <label id="area" isSelectable = "true"/>
- <label id="volume" isSelectable = "true"/>
-</source>
--- /dev/null
+
+ .. _tui_basic_properties:
+
+Get basic properties
+====================
+
+.. literalinclude:: examples/basic_properties.py
+ :linenos:
+ :language: python
+
+:download:`Download this script <examples/basic_properties.py>`
+
--- /dev/null
+import os
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
+properties = model.getBasicProperties(Part_1_doc,model.selection("SOLID", "Box_1_1"))
+print(" lenght: ", properties[0])
+print(" area: ", properties[1])
+print(" volume: ", properties[2])
+model.end()
\ No newline at end of file
- **Object** contains an object selected in 3D OCC viewer or object browser.
The basic properties displayed can be selected.
+
+**TUI Command**:
+
+.. py:function:: model.GetBasicProperties(Part_doc, shape)
+
+ :param part: The current part object.
+ :param object: A shape in format *model.selection("type", shape)*.
+ :return: list containing lenght, area and volume.
+
+**See Also** a sample TUI Script of :ref:`tui_basic_properties` operation.
\ No newline at end of file
--- /dev/null
+<source>
+ <shape_selector id="main_object"
+ label="Object"
+ tooltip="Select a object"
+ shape_types="edges faces solids compsolids"
+ default=""
+ geometrical_selection="true">
+ <validator id="GeomValidators_ShapeType" parameters="line,edge,wire,face,shell,solid,compsolid,compound"/>
+ </shape_selector>
+ <label id="lenght" isSelectable = "true"/>
+ <label id="area" isSelectable = "true"/>
+ <label id="volume" isSelectable = "true"/>
+</source>
</group>
</workbench>
<workbench id="Inspection">
-
<group id="Calculation">
<feature id="GeometryCalculation" title="Geometry Calculation" tooltip="Calculate properties of objects"
icon="icons/Features/basicproperties.png" helpfile="geometryCalculationFeature.html" abort_confirmation="false">
- <source path="GeometryCalculation_widget.xml"/>
+ <source path="geometry_calculation_widget.xml"/>
</feature>
<feature id="Measurement" title="Measurement" tooltip="Calculate properties of objects"
icon="icons/Features/measurement.png" helpfile="measurementFeature.html" abort_confirmation="false">
#include <Standard_ErrorHandler.hxx>
//=================================================================================================
-bool GetBasicProperties( const std::shared_ptr<GeomAPI_Shape>& theShape,
- const double theTolerance,
- Standard_Real& theLength,
- Standard_Real& theSurfArea,
- Standard_Real& theVolume,
- std::string& theError)
+bool GetBasicProperties(const std::shared_ptr<GeomAPI_Shape>& theShape,
+ const double theTolerance,
+ Standard_Real& theLength,
+ Standard_Real& theSurfArea,
+ Standard_Real& theVolume,
+ std::string& theError)
{
#ifdef _DEBUG
/// \param theVolume Volume calculated
/// \param theError error
GEOMALGOAPI_EXPORT
-bool GetBasicProperties( const std::shared_ptr<GeomAPI_Shape>& theShape,
- const Standard_Real theTolerance,
- Standard_Real& theLength,
- Standard_Real& theSurfArea,
- Standard_Real& theVolume,
- std::string& theError);
+bool GetBasicProperties(const std::shared_ptr<GeomAPI_Shape>& theShape,
+ const Standard_Real theTolerance,
+ Standard_Real& theLength,
+ Standard_Real& theSurfArea,
+ Standard_Real& theVolume,
+ std::string& theError);
#endif
SET(PROJECT_LIBRARIES
Config
GeomAPI
- ${OpenCASCADE_ApplicationFramework_LIBRARIES}
)
SET(CMAKE_SWIG_FLAGS -threads -w325,321,362,383,302,403,451,473)
ADD_DEFINITIONS(-DMODELAPI_EXPORTS)
${PROJECT_SOURCE_DIR}/src/GeomAPI
${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI
${PROJECT_SOURCE_DIR}/src/Locale
- ${OpenCASCADE_INCLUDE_DIR}
- ${OpenCASCADE_DataExchange_LIBRARIES}
- ${OpenCASCADE_ModelingAlgorithms_LIBRARIES}
- ${OpenCASCADE_ApplicationFramework_LIBRARIES}
)