1 // Copyright (C) 2018-2019 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 "FeaturesAPI_Measurement.h"
22 #include <FeaturesPlugin_Measurement.h>
23 #include <ModelAPI_AttributeDoubleArray.h>
24 #include <ModelHighAPI_Services.h>
25 #include <ModelHighAPI_Tools.h>
27 double measureLength(const std::shared_ptr<ModelAPI_Document>& thePart,
28 const ModelHighAPI_Selection& theEdge)
30 FeaturePtr aMeasure = thePart->addFeature(FeaturesPlugin_Measurement::ID());
31 fillAttribute(FeaturesPlugin_Measurement::MEASURE_LENGTH(),
32 aMeasure->string(FeaturesPlugin_Measurement::MEASURE_KIND()));
33 fillAttribute(theEdge, aMeasure->selection(FeaturesPlugin_Measurement::EDGE_FOR_LENGTH_ID()));
37 AttributeDoubleArrayPtr aResult = std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(
38 aMeasure->attribute(FeaturesPlugin_Measurement::RESULT_VALUES_ID()));
39 double aValue = aResult->size() ? aResult->value(0) : -1.0;
41 // perform removing macro feature Measurement
42 thePart->removeFeature(aMeasure);
48 double measureDistance(const std::shared_ptr<ModelAPI_Document>& thePart,
49 const ModelHighAPI_Selection& theFrom,
50 const ModelHighAPI_Selection& theTo)
52 FeaturePtr aMeasure = thePart->addFeature(FeaturesPlugin_Measurement::ID());
53 fillAttribute(FeaturesPlugin_Measurement::MEASURE_DISTANCE(),
54 aMeasure->string(FeaturesPlugin_Measurement::MEASURE_KIND()));
55 fillAttribute(theFrom,
56 aMeasure->selection(FeaturesPlugin_Measurement::DISTANCE_FROM_OBJECT_ID()));
57 fillAttribute(theTo, aMeasure->selection(FeaturesPlugin_Measurement::DISTANCE_TO_OBJECT_ID()));
61 AttributeDoubleArrayPtr aResult = std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(
62 aMeasure->attribute(FeaturesPlugin_Measurement::RESULT_VALUES_ID()));
63 double aValue = aResult->size() ? aResult->value(0) : -1.0;
65 // perform removing macro feature Measurement
66 thePart->removeFeature(aMeasure);
72 double measureRadius(const std::shared_ptr<ModelAPI_Document>& thePart,
73 const ModelHighAPI_Selection& theObject)
75 FeaturePtr aMeasure = thePart->addFeature(FeaturesPlugin_Measurement::ID());
76 fillAttribute(FeaturesPlugin_Measurement::MEASURE_RADIUS(),
77 aMeasure->string(FeaturesPlugin_Measurement::MEASURE_KIND()));
78 fillAttribute(theObject, aMeasure->selection(FeaturesPlugin_Measurement::CIRCULAR_OBJECT_ID()));
82 AttributeDoubleArrayPtr aResult = std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(
83 aMeasure->attribute(FeaturesPlugin_Measurement::RESULT_VALUES_ID()));
84 double aValue = aResult->size() ? aResult->value(0) : -1.0;
86 // perform removing macro feature Measurement
87 thePart->removeFeature(aMeasure);
93 std::list<double> measureAngle(const std::shared_ptr<ModelAPI_Document>& thePart,
94 const ModelHighAPI_Selection& theFrom,
95 const ModelHighAPI_Selection& theTo)
97 FeaturePtr aMeasure = thePart->addFeature(FeaturesPlugin_Measurement::ID());
98 fillAttribute(FeaturesPlugin_Measurement::MEASURE_ANGLE(),
99 aMeasure->string(FeaturesPlugin_Measurement::MEASURE_KIND()));
100 fillAttribute(theFrom, aMeasure->selection(FeaturesPlugin_Measurement::ANGLE_FROM_EDGE_ID()));
101 fillAttribute(theTo, aMeasure->selection(FeaturesPlugin_Measurement::ANGLE_TO_EDGE_ID()));
105 AttributeDoubleArrayPtr aResult = std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(
106 aMeasure->attribute(FeaturesPlugin_Measurement::RESULT_VALUES_ID()));
107 std::list<double> aValues;
108 for (int i = 0, n = aResult->size(); i < n; ++i)
109 aValues.push_back(aResult->value(i));
111 // perform removing macro feature Measurement
112 thePart->removeFeature(aMeasure);
118 double measureAngle(const std::shared_ptr<ModelAPI_Document>& thePart,
119 const ModelHighAPI_Selection& thePoint1,
120 const ModelHighAPI_Selection& thePoint2,
121 const ModelHighAPI_Selection& thePoint3)
123 FeaturePtr aMeasure = thePart->addFeature(FeaturesPlugin_Measurement::ID());
124 fillAttribute(FeaturesPlugin_Measurement::MEASURE_ANGLE_POINTS(),
125 aMeasure->string(FeaturesPlugin_Measurement::MEASURE_KIND()));
126 fillAttribute(thePoint1, aMeasure->selection(FeaturesPlugin_Measurement::ANGLE_POINT1_ID()));
127 fillAttribute(thePoint2, aMeasure->selection(FeaturesPlugin_Measurement::ANGLE_POINT2_ID()));
128 fillAttribute(thePoint3, aMeasure->selection(FeaturesPlugin_Measurement::ANGLE_POINT3_ID()));
132 AttributeDoubleArrayPtr aResult = std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(
133 aMeasure->attribute(FeaturesPlugin_Measurement::RESULT_VALUES_ID()));
134 double aValue = aResult->size() ? aResult->value(0) : -1.0;
136 // perform removing macro feature Measurement
137 thePart->removeFeature(aMeasure);