Salome HOME
updated copyright message
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_PointCloudOnFace.cpp
1 // Copyright (C) 2014-2023  CEA, EDF
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "FeaturesPlugin_PointCloudOnFace.h"
21
22 #include <ModelAPI_AttributeSelection.h>
23 #include <ModelAPI_AttributeString.h>
24 #include <ModelAPI_AttributeInteger.h>
25 #include <ModelAPI_Data.h>
26 #include <ModelAPI_Session.h>
27 #include <ModelAPI_Validator.h>
28 #include <Config_PropManager.h>
29 #include <GeomAlgoAPI_PointCloudOnFace.h>
30 #include <ModelAPI_ResultConstruction.h>
31
32 #include <iomanip>
33 #include <sstream>
34
35 //=================================================================================================
36 FeaturesPlugin_PointCloudOnFace::FeaturesPlugin_PointCloudOnFace()
37 {
38 }
39
40 //=================================================================================================
41 void FeaturesPlugin_PointCloudOnFace::initAttributes()
42 {
43   // attribute for object selected
44   data()->addAttribute(FACE_SELECTED_ID(), ModelAPI_AttributeSelection::typeId());
45   data()->addAttribute(NUMBER_ID(), ModelAPI_AttributeInteger::typeId());
46 }
47
48 //=================================================================================================
49 void FeaturesPlugin_PointCloudOnFace::attributeChanged(const std::string& /*theID*/)
50 {
51 }
52
53 //=================================================================================================
54 void FeaturesPlugin_PointCloudOnFace::execute()
55 {
56
57   AttributeSelectionPtr aSelectionFace = selection(FACE_SELECTED_ID());
58
59   GeomShapePtr aShape;
60
61   if (aSelectionFace && aSelectionFace->isInitialized()) {
62     aShape = aSelectionFace->value();
63     if (!aShape && aSelectionFace->context())
64       aShape = aSelectionFace->context()->shape();
65   }
66
67   // Getting number of points
68   int aNbPnts = integer(FeaturesPlugin_PointCloudOnFace::NUMBER_ID())->value();
69
70   if (aShape && aNbPnts >= 2) {
71     std::string aError;
72     std::shared_ptr<GeomAPI_Shape> aPoints(new GeomAPI_Shape);
73     if (!GeomAlgoAPI_PointCloudOnFace::PointCloud(aShape,
74                                                   aNbPnts,
75                                                   aPoints,
76                                                   aError))
77       setError("Error in points calculation :" +  aError);
78
79     ResultConstructionPtr aConstr = document()->createConstruction(data());
80     aConstr->setInfinite(true);
81     aConstr->setShape(aPoints);
82     setResult(aConstr);
83   }
84 }