1 // Copyright (C) 2018-20xx 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "FeaturesAPI_Measurement.h"
23 #include <FeaturesPlugin_Measurement.h>
24 #include <ModelAPI_AttributeDoubleArray.h>
25 #include <ModelHighAPI_Services.h>
26 #include <ModelHighAPI_Tools.h>
28 double measureLength(const std::shared_ptr<ModelAPI_Document>& thePart,
29 const ModelHighAPI_Selection& theEdge)
31 FeaturePtr aMeasure = thePart->addFeature(FeaturesPlugin_Measurement::ID());
32 fillAttribute(FeaturesPlugin_Measurement::MEASURE_LENGTH(),
33 aMeasure->string(FeaturesPlugin_Measurement::MEASURE_KIND()));
34 fillAttribute(theEdge, aMeasure->selection(FeaturesPlugin_Measurement::EDGE_FOR_LENGTH_ID()));
38 AttributeDoubleArrayPtr aResult = std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(
39 aMeasure->attribute(FeaturesPlugin_Measurement::RESULT_VALUES_ID()));
40 double aValue = aResult->size() ? aResult->value(0) : -1.0;
42 // perform removing macro feature Measurement
43 thePart->removeFeature(aMeasure);
49 double measureDistance(const std::shared_ptr<ModelAPI_Document>& thePart,
50 const ModelHighAPI_Selection& theFrom,
51 const ModelHighAPI_Selection& theTo)
53 FeaturePtr aMeasure = thePart->addFeature(FeaturesPlugin_Measurement::ID());
54 fillAttribute(FeaturesPlugin_Measurement::MEASURE_DISTANCE(),
55 aMeasure->string(FeaturesPlugin_Measurement::MEASURE_KIND()));
56 fillAttribute(theFrom,
57 aMeasure->selection(FeaturesPlugin_Measurement::DISTANCE_FROM_OBJECT_ID()));
58 fillAttribute(theTo, aMeasure->selection(FeaturesPlugin_Measurement::DISTANCE_TO_OBJECT_ID()));
62 AttributeDoubleArrayPtr aResult = std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(
63 aMeasure->attribute(FeaturesPlugin_Measurement::RESULT_VALUES_ID()));
64 double aValue = aResult->size() ? aResult->value(0) : -1.0;
66 // perform removing macro feature Measurement
67 thePart->removeFeature(aMeasure);
73 double measureRadius(const std::shared_ptr<ModelAPI_Document>& thePart,
74 const ModelHighAPI_Selection& theObject)
76 FeaturePtr aMeasure = thePart->addFeature(FeaturesPlugin_Measurement::ID());
77 fillAttribute(FeaturesPlugin_Measurement::MEASURE_RADIUS(),
78 aMeasure->string(FeaturesPlugin_Measurement::MEASURE_KIND()));
79 fillAttribute(theObject, aMeasure->selection(FeaturesPlugin_Measurement::CIRCULAR_OBJECT_ID()));
83 AttributeDoubleArrayPtr aResult = std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(
84 aMeasure->attribute(FeaturesPlugin_Measurement::RESULT_VALUES_ID()));
85 double aValue = aResult->size() ? aResult->value(0) : -1.0;
87 // perform removing macro feature Measurement
88 thePart->removeFeature(aMeasure);
94 std::list<double> measureAngle(const std::shared_ptr<ModelAPI_Document>& thePart,
95 const ModelHighAPI_Selection& theFrom,
96 const ModelHighAPI_Selection& theTo)
98 FeaturePtr aMeasure = thePart->addFeature(FeaturesPlugin_Measurement::ID());
99 fillAttribute(FeaturesPlugin_Measurement::MEASURE_ANGLE(),
100 aMeasure->string(FeaturesPlugin_Measurement::MEASURE_KIND()));
101 fillAttribute(theFrom, aMeasure->selection(FeaturesPlugin_Measurement::ANGLE_FROM_EDGE_ID()));
102 fillAttribute(theTo, aMeasure->selection(FeaturesPlugin_Measurement::ANGLE_TO_EDGE_ID()));
106 AttributeDoubleArrayPtr aResult = std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(
107 aMeasure->attribute(FeaturesPlugin_Measurement::RESULT_VALUES_ID()));
108 std::list<double> aValues;
109 for (int i = 0, n = aResult->size(); i < n; ++i)
110 aValues.push_back(aResult->value(i));
112 // perform removing macro feature Measurement
113 thePart->removeFeature(aMeasure);
119 double measureAngle(const std::shared_ptr<ModelAPI_Document>& thePart,
120 const ModelHighAPI_Selection& thePoint1,
121 const ModelHighAPI_Selection& thePoint2,
122 const ModelHighAPI_Selection& thePoint3)
124 FeaturePtr aMeasure = thePart->addFeature(FeaturesPlugin_Measurement::ID());
125 fillAttribute(FeaturesPlugin_Measurement::MEASURE_ANGLE_POINTS(),
126 aMeasure->string(FeaturesPlugin_Measurement::MEASURE_KIND()));
127 fillAttribute(thePoint1, aMeasure->selection(FeaturesPlugin_Measurement::ANGLE_POINT1_ID()));
128 fillAttribute(thePoint2, aMeasure->selection(FeaturesPlugin_Measurement::ANGLE_POINT2_ID()));
129 fillAttribute(thePoint3, aMeasure->selection(FeaturesPlugin_Measurement::ANGLE_POINT3_ID()));
133 AttributeDoubleArrayPtr aResult = std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(
134 aMeasure->attribute(FeaturesPlugin_Measurement::RESULT_VALUES_ID()));
135 double aValue = aResult->size() ? aResult->value(0) : -1.0;
137 // perform removing macro feature Measurement
138 thePart->removeFeature(aMeasure);