1 // Copyright (C) 2018-2022 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "FeaturesPlugin_PointCoordinates.h"
22 #include <ModelAPI_AttributeSelection.h>
23 #include <ModelAPI_AttributeDoubleArray.h>
25 #include <ModelAPI_AttributeString.h>
26 #include <ModelAPI_Data.h>
27 #include <ModelAPI_Session.h>
29 #include <Config_PropManager.h>
31 #include <GeomAPI_Pnt.h>
32 #include <GeomAPI_Shape.h>
33 #include <GeomAPI_Vertex.h>
35 #include <GeomAlgoAPI_PointBuilder.h>
40 FeaturesPlugin_PointCoordinates::FeaturesPlugin_PointCoordinates()
44 void FeaturesPlugin_PointCoordinates::initAttributes()
46 // attribute for point selected
47 data()->addAttribute(POINT_SELECTED_ID(), ModelAPI_AttributeSelection::typeId());
49 // attribute for x, y and z coordinates
50 data()->addAttribute(X_COORD_ID(), ModelAPI_AttributeString::typeId());
51 data()->addAttribute(Y_COORD_ID(), ModelAPI_AttributeString::typeId());
52 data()->addAttribute(Z_COORD_ID(), ModelAPI_AttributeString::typeId());
54 // attributes for result message and values
55 data()->addAttribute(RESULT_VALUES_ID(), ModelAPI_AttributeDoubleArray::typeId());
56 data()->realArray(RESULT_VALUES_ID())->setSize(3);
59 void FeaturesPlugin_PointCoordinates::execute()
63 void FeaturesPlugin_PointCoordinates::attributeChanged(const std::string& theID)
65 if (theID == POINT_SELECTED_ID()) {
66 AttributeSelectionPtr aSelection = selection(POINT_SELECTED_ID());
69 if (aSelection && aSelection->isInitialized()) {
70 aShape = aSelection->value();
71 if (!aShape && aSelection->context())
72 aShape = aSelection->context()->shape();
75 AttributeDoubleArrayPtr aValues =
76 std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(attribute(RESULT_VALUES_ID()));
77 std::stringstream streamx;
78 std::stringstream streamy;
79 std::stringstream streamz;
81 aPoint = GeomAlgoAPI_PointBuilder::point(aShape);
82 streamx << std::setprecision(14) << aPoint->x();
83 aValues->setValue(0, aPoint->x());
84 streamy << std::setprecision(14) << aPoint->y();
85 aValues->setValue(1, aPoint->y());
86 streamz << std::setprecision(14) << aPoint->z();
87 aValues->setValue(2, aPoint->z());
90 string(X_COORD_ID() )->setValue( "X = " + streamx.str() );
91 string(Y_COORD_ID() )->setValue( "Y = " + streamy.str() );
92 string(Z_COORD_ID() )->setValue( "Z = " + streamz.str() );