MAYBE_UNUSED const static char* ATTR_ICON = FEATURE_ICON;
MAYBE_UNUSED const static char* ATTR_LABEL = "label";
MAYBE_UNUSED const static char* ATTR_STYLE_SHEET = "styleSheet";
+MAYBE_UNUSED const static char* ATTR_IS_SELECTABLE = "isSelectable";
MAYBE_UNUSED const static char* ATTR_HTML_STYLE = "isHTML";
MAYBE_UNUSED const static char* ATTR_DEFAULT = "default";
MAYBE_UNUSED const static char* ATTR_INTERNAL = "internal";
FeaturesAPI_Copy.h
FeaturesAPI_ImportResult.h
FeaturesAPI_Defeaturing.h
+ FeaturesAPI_PointCoordinates.h
)
SET(PROJECT_SOURCES
FeaturesAPI_Copy.cpp
FeaturesAPI_ImportResult.cpp
FeaturesAPI_Defeaturing.cpp
+ FeaturesAPI_PointCoordinates.cpp
)
SET(PROJECT_LIBRARIES
%include "FeaturesAPI_RemoveResults.h"
%include "FeaturesAPI_Copy.h"
%include "FeaturesAPI_ImportResult.h"
+%include "FeaturesAPI_PointCoordinates.h"
--- /dev/null
+// Copyright (C) 2018-2020 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, or (at your option) any later version.
+//
+// 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 "FeaturesAPI_PointCoordinates.h"
+
+#include <FeaturesPlugin_PointCoordinates.h>
+#include <ModelAPI_AttributeDoubleArray.h>
+#include <ModelHighAPI_Services.h>
+#include <ModelHighAPI_Tools.h>
+
+std::list<double> getPointCoordinates(const std::shared_ptr<ModelAPI_Document>& thePart,
+ const ModelHighAPI_Selection& thePoint)
+{
+ FeaturePtr aPointCoordFeat = thePart->addFeature(FeaturesPlugin_PointCoordinates::ID());
+
+ fillAttribute(thePoint, aPointCoordFeat
+ ->selection(FeaturesPlugin_PointCoordinates::POINT_SELECTED_ID()));
+ std::list<double> res;
+
+ // obtain result
+ AttributeDoubleArrayPtr aResult = std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(
+ aPointCoordFeat->attribute(FeaturesPlugin_PointCoordinates::RESULT_VALUES_ID()));
+
+ for ( int i : {0, 1, 2})
+ res.push_back( aResult->value(i));
+
+ return res;
+}
+
--- /dev/null
+// Copyright (C) 2018-2020 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, or (at your option) any later version.
+//
+// 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 FeaturesAPI_PointCoordinates_H_
+#define FeaturesAPI_PointCoordinates_H_
+
+#include "FeaturesAPI.h"
+
+#include <list>
+#include <memory>
+
+class ModelAPI_Document;
+class ModelHighAPI_Selection;
+
+/// \ingroup CPPHighAPI
+/// \brief Get the point coordinates.
+FEATURESAPI_EXPORT
+std::list<double> getPointCoordinates(const std::shared_ptr<ModelAPI_Document>& thePart,
+ const ModelHighAPI_Selection& thePoint);
+
+#endif // FeaturesAPI_PointCoordinates_H_
#include "FeaturesAPI_RemoveResults.h"
#include "FeaturesAPI_Copy.h"
#include "FeaturesAPI_ImportResult.h"
+ #include "FeaturesAPI_PointCoordinates.h"
#endif // FeaturesAPI_swig_H_
INCLUDE(Common)
INCLUDE(UnitTest)
+
SET(PROJECT_HEADERS
FeaturesPlugin.h
FeaturesPlugin_Plugin.h
FeaturesPlugin_ImportResult.h
FeaturesPlugin_Defeaturing.h
FeaturesPlugin_VersionedChFi.h
+ FeaturesPlugin_PointCoordinates.h
)
SET(PROJECT_SOURCES
FeaturesPlugin_ImportResult.cpp
FeaturesPlugin_Defeaturing.cpp
FeaturesPlugin_VersionedChFi.cpp
+ FeaturesPlugin_PointCoordinates.cpp
)
SET(XML_RESOURCES
copy_widget.xml
import_result_widget.xml
defeaturing_widget.xml
+ point_coordinates_widget.xml
)
SET(TEXT_RESOURCES
../GeomAPI
../GeomAlgoAPI
../GeomValidators
+ ../ModuleBase
../Events
../Config
${OpenCASCADE_INCLUDE_DIR}
Test20245_2.py
Test20245_3.py
Test20247.py
+ TestPointCoordinates.py
)
#include <FeaturesPlugin_Fillet1D.h>
#include <FeaturesPlugin_Intersection.h>
#include <FeaturesPlugin_Measurement.h>
+#include <FeaturesPlugin_PointCoordinates.h>
#include <FeaturesPlugin_MultiRotation.h>
#include <FeaturesPlugin_MultiTranslation.h>
#include <FeaturesPlugin_Partition.h>
return FeaturePtr(new FeaturesPlugin_ImportResult);
} else if (theFeatureID == FeaturesPlugin_Defeaturing::ID()) {
return FeaturePtr(new FeaturesPlugin_Defeaturing);
+ } else if (theFeatureID == FeaturesPlugin_PointCoordinates::ID()) {
+ return FeaturePtr(new FeaturesPlugin_PointCoordinates);
}
--- /dev/null
+// Copyright (C) 2018-2020 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, or (at your option) any later version.
+//
+// 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 "FeaturesPlugin_PointCoordinates.h"
+
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeDoubleArray.h>
+
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Session.h>
+
+#include <Config_PropManager.h>
+
+#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Shape.h>
+#include <GeomAPI_Vertex.h>
+
+#include <GeomAlgoAPI_PointBuilder.h>
+
+#include <iomanip>
+#include <sstream>
+
+FeaturesPlugin_PointCoordinates::FeaturesPlugin_PointCoordinates()
+{
+}
+
+void FeaturesPlugin_PointCoordinates::initAttributes()
+{
+ // attribute for point selected
+ data()->addAttribute(POINT_SELECTED_ID(), ModelAPI_AttributeSelection::typeId());
+
+ // attribute for x, y and z coordinates
+ data()->addAttribute(X_COORD_ID(), ModelAPI_AttributeString::typeId());
+ data()->addAttribute(Y_COORD_ID(), ModelAPI_AttributeString::typeId());
+ data()->addAttribute(Z_COORD_ID(), ModelAPI_AttributeString::typeId());
+
+ // attributes for result message and values
+ data()->addAttribute(RESULT_VALUES_ID(), ModelAPI_AttributeDoubleArray::typeId());
+ data()->realArray(RESULT_VALUES_ID())->setSize(3);
+}
+
+void FeaturesPlugin_PointCoordinates::execute()
+{
+}
+
+void FeaturesPlugin_PointCoordinates::attributeChanged(const std::string& theID)
+{
+ if (theID == POINT_SELECTED_ID()) {
+ AttributeSelectionPtr aSelection = selection(POINT_SELECTED_ID());
+ GeomShapePtr aShape;
+ GeomPointPtr aPoint;
+ if (aSelection && aSelection->isInitialized()) {
+ aShape = aSelection->value();
+ if (!aShape && aSelection->context())
+ aShape = aSelection->context()->shape();
+ }
+
+ AttributeDoubleArrayPtr aValues =
+ std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(attribute(RESULT_VALUES_ID()));
+ std::stringstream streamx;
+ std::stringstream streamy;
+ std::stringstream streamz;
+ if (aShape) {
+ aPoint = GeomAlgoAPI_PointBuilder::point(aShape);
+ streamx << std::setprecision(14) << aPoint->x();
+ aValues->setValue(0, aPoint->x());
+ streamy << std::setprecision(14) << aPoint->y();
+ aValues->setValue(1, aPoint->y());
+ streamz << std::setprecision(14) << aPoint->z();
+ aValues->setValue(2, aPoint->z());
+ }
+
+ string(X_COORD_ID() )->setValue( "X = " + streamx.str() );
+ string(Y_COORD_ID() )->setValue( "Y = " + streamy.str() );
+ string(Z_COORD_ID() )->setValue( "Z = " + streamz.str() );
+ }
+
+}
+
--- /dev/null
+// Copyright (C) 2018-2020 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, or (at your option) any later version.
+//
+// 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 FeaturesPlugin_PointCoordinates_H_
+#define FeaturesPlugin_PointCoordinates_H_
+
+#include "FeaturesPlugin.h"
+#include <ModelAPI_Feature.h>
+
+#include <GeomAPI_IPresentable.h>
+#include <GeomAPI_IScreenParams.h>
+
+/// \class FeaturesPlugin_PointCoordinates
+/// \ingroup Plugins
+/// \brief Feature to view point coordinates.
+
+class FeaturesPlugin_PointCoordinates : public ModelAPI_Feature
+{
+public:
+ inline static const std::string& ID()
+ {
+ static const std::string MY_ID("PointCoordinates");
+ return MY_ID;
+ }
+
+ /// Attribute name for point selected.
+ inline static const std::string& POINT_SELECTED_ID()
+ {
+ static const std::string MY_POINT_SELECTED_ID("point_selected");
+ return MY_POINT_SELECTED_ID;
+ }
+
+ /// Attribute name for x coordinate.
+ inline static const std::string& X_COORD_ID()
+ {
+ static const std::string MY_X_COORD_ID("xcoordinate");
+ return MY_X_COORD_ID;
+ }
+
+ /// Attribute name for y coordinate.
+ inline static const std::string& Y_COORD_ID()
+ {
+ static const std::string MY_Y_COORD_ID("ycoordinate");
+ return MY_Y_COORD_ID;
+ }
+
+ /// Attribute name for z coordinate.
+ inline static const std::string& Z_COORD_ID()
+ {
+ static const std::string MY_Z_COORD_ID("zcoordinate");
+ return MY_Z_COORD_ID;
+ }
+
+ /// Attribute name for values of result.
+ inline static const std::string& RESULT_VALUES_ID()
+ {
+ static const std::string MY_RESULT_VALUES_ID("result_values");
+ return MY_RESULT_VALUES_ID;
+ }
+
+ /// \return the kind of a feature.
+ virtual const std::string& getKind()
+ {
+ return ID();
+ }
+
+ /// Performs the algorithm and stores results it in the data structure.
+ FEATURESPLUGIN_EXPORT virtual void execute();
+
+ /// Request for initialization of data model of the feature: adding all attributes
+ FEATURESPLUGIN_EXPORT virtual void initAttributes();
+
+ /// Called on change of any argument-attribute of this object
+ /// \param theID identifier of changed attribute
+ FEATURESPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
+
+ /// Reimplemented from ModelAPI_Feature::isMacro(). Returns true.
+ FEATURESPLUGIN_EXPORT virtual bool isMacro() const { return true; }
+
+ /// Use plugin manager for features creation
+ FeaturesPlugin_PointCoordinates();
+
+};
+
+#endif
<source>Measurement</source>
<translation>Mesure</translation>
</message>
+ <message>
+ <source>Point coordinates</source>
+ <translation>Coordonnées d'un point</translation>
+ </message>
<message>
<source>Placement</source>
<translation>Placement</translation>
<translation>Deuxième direction</translation>
</message>
</context>
-
+ <!-- PointCoordinates -->
+ <context>
+ <name>PointCoordinates</name>
+ <message>
+ <source>Point coordinates</source>
+ <translation>Coordonnées d'un point</translation>
+ </message>
+ </context>
<!-- Measurement -->
<context>
<name>Measurement</name>
--- /dev/null
+# Copyright (C) 2014-2020 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, or (at your option) any later version.
+#
+# 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
+#
+
+"""
+ Unit test of ...
+"""
+#=========================================================================
+# Initialization of the test
+#=========================================================================
+
+import os
+import math
+
+from salome.shaper import model
+
+__updated__ = "2020-11-12"
+
+#=========================================================================
+# test get point coordinates
+#=========================================================================
+def test_point_coordinates():
+
+ model.begin()
+ file_path = os.path.join(os.getenv("DATA_DIR"),"Shapes","Brep","box1.brep")
+ partSet = model.moduleDocument()
+ Part_1 = model.addPart(partSet)
+ Part_1_doc = Part_1.document()
+ Import_1 = model.addImport(Part_1_doc,file_path)
+ model.do()
+
+ myDelta = 1e-6
+ coordinates = model.getPointCoordinates(Part_1_doc,model.selection("VERTEX", "[box1_1/Shape_2][box1_1/Shape_3][box1_1/Shape_6]"))
+
+ print(" x: ", coordinates[0])
+ print(" y: ", coordinates[1])
+ print(" z: ", coordinates[2])
+
+ aRef = 200
+ aRes = coordinates[0]
+ assert (math.fabs(aRes - aRef) < myDelta), "The coordinate X is wrong: expected = {0}, real = {1}".format(aRef, aRes)
+
+ aRef = 0
+ aRes= coordinates[1]
+ assert (math.fabs(aRes - aRef) < myDelta), "The coordinate Y is wrong: expected = {0}, real = {1}".format(aRef, aRes)
+
+ aRef = 200
+ aRes = coordinates[2]
+ assert (math.fabs(aRes - aRef) < myDelta), "The coordinate Z is wrong: expected = {0}, real = {1}".format(aRef, aRes)
+
+
+if __name__ == '__main__':
+
+ test_point_coordinates()
+
+ #=========================================================================
+ # End of test
+ #=========================================================================
extrusionCutFeature.rst
extrusionFeature.rst
extrusionFuseFeature.rst
- filletFeature.rst
fillet1dFeature.rst
+ filletFeature.rst
fuseFeatureFaces.rst
importResultFeature.rst
linearCopyFeature.rst
measurementFeature.rst
pipeFeature.rst
placementFeature.rst
+ pointCoordinatesFeature.rst
recoverFeature.rst
removeSubShapesFeature.rst
revolutionCutFeature.rst
--- /dev/null
+
+ .. _tui_point_coordinates:
+
+Get point coordinates
+=====================
+
+.. literalinclude:: examples/point_coordinates.py
+ :linenos:
+ :language: python
+
+:download:`Download this script <examples/point_coordinates.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)
+coordinates = model.getPointCoordinates(Part_1_doc,model.selection("VERTEX", "[Box_1_1/Front][Box_1_1/Left][Box_1_1/Top]"))
+print(" x: ", coordinates[0])
+print(" y: ", coordinates[1])
+print(" z: ", coordinates[2])
+model.end()
--- /dev/null
+.. |point_coord.icon| image:: images/point_coord.png
+
+Point Coordinates
+=================
+
+The **Points coordinates** feature displays the coordinates of a selected point.
+
+The coordinates are displayed in the property panel.
+
+**Apply** button does not generate any result and has the same effect as **Cancel** for this feature.
+
+To display Point coordinates in the active part:
+
+#. select in the Main Menu *Inspection - > Point coordinates* item or
+#. click |point_coord.icon| **Points coordinates** button in the toolbar
+
+The coordinates can be displayed for a selected point in the property panel :
+
+.. figure:: images/pointCoordinatesPropertyPanel.png
+ :align: center
+
+ Point coordinates
+
+Input fields:
+
+- Input field contains a point selected in 3D OCC viewer or object browser.
+
+Note, the coordinates displayed can be selected.
+
+**TUI Command**:
+
+.. py:function:: model.getPointCoordinates(Part_doc, point)
+
+ :param part: The current part object.
+ :param object: A point in format *model.selection("VERTEX", shape)*.
+ :return: list of coordinates.
+
+**See Also** a sample TUI Script of :ref:`tui_point_coordinates` operation.
\ No newline at end of file
</group>
</workbench>
<workbench id="Inspection">
- <group id="Measurement">
+ <group id="PointCoordinates">
+ <feature id="PointCoordinates" title="Point coordinates" tooltip="View point coordinate"
+ icon="icons/Features/point_coord.png" helpfile="pointCoordinatesFeature.html" abort_confirmation="false">
+ <source path="point_coordinates_widget.xml"/>
+ </feature>
+ </group>
+ <group id="Calculation">
<feature id="Measurement" title="Measurement" tooltip="Calculate properties of objects"
icon="icons/Features/measurement.png" helpfile="measurementFeature.html" abort_confirmation="false">
<source path="measurement_widget.xml"/>
--- /dev/null
+<source>
+ <shape_selector id="point_selected"
+ icon="icons/Features/point.png"
+ label="Edge"
+ tooltip="Select a point"
+ shape_types="vertex"
+ default="">
+ <validator id="GeomValidators_ShapeType" parameters="vertex"/>
+ <validator id="GeomValidators_ConstructionComposite"/>
+ </shape_selector>
+ <label id="xcoordinate" isSelectable="true"/>
+ <label id="ycoordinate" isSelectable="true"/>
+ <label id="zcoordinate" isSelectable="true"/>
+</source>
std::string aStyleSheet = theData->getProperty(ATTR_STYLE_SHEET);
if (!aStyleSheet.empty())
myLabel->setStyleSheet(QString("QLabel {%1}").arg(aStyleSheet.c_str()));
+
+ aStyleSheet = theData->getProperty(ATTR_IS_SELECTABLE);
+ if ( aStyleSheet == "true")
+ myLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
}
ModuleBase_WidgetLabel::~ModuleBase_WidgetLabel()
from FeaturesAPI import addFillet, addChamfer
from FeaturesAPI import addFusionFaces
from FeaturesAPI import measureLength, measureDistance, measureRadius, measureAngle
+from FeaturesAPI import getPointCoordinates
from FeaturesAPI import addRemoveResults
from FeaturesAPI import addCopy, addImportResult
from FeaturesAPI import addDefeaturing
}
int aMenu = createMenu(tr("Inspection"), -1, -1, 30);
- int aSubMenu = createMenu(tr("Information"), aMenu, -1, -1, 0);
int aId = getNextCommandId();
myActionsList.append(aId);
aTip, QKeySequence(), aDesk, true, this, SLOT(onWhatIs(bool)));
myWhatIsAction->setStatusTip(aTip);
myWhatIsAction->setData("INSPECTION_CMD");
- createMenu(aId, aSubMenu, 0);
+ createMenu(aId, aMenu, 0);
QString aToolName = tr("Inspection");
int aTool = createTool(aToolName);
#ifdef _DEBUG
int aItemId =
#endif
- createMenu(aId, aWBMenu);
+
+ if( theId == "PointCoordinates" )
+ createMenu(separator(), aWBMenu);
+
+ createMenu(aId, aWBMenu);
+
if (isAddSeparator)
createMenu(separator(), aWBMenu);