1 // Copyright (C) 2014-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_NormalToFace.h"
22 #include <ModelAPI_AttributeSelection.h>
23 #include <ModelAPI_AttributeString.h>
24 #include <ModelAPI_Data.h>
25 #include <ModelAPI_Session.h>
26 #include <ModelAPI_Validator.h>
27 #include <GeomAPI_Vertex.h>
28 #include <GeomAPI_Edge.h>
29 #include <Config_PropManager.h>
30 #include <GeomAlgoAPI_NormalToFace.h>
31 #include <GeomAPI_Lin.h>
32 #include <GeomAPI_Dir.h>
33 #include <GeomAlgoAPI_EdgeBuilder.h>
34 #include <ModelAPI_ResultConstruction.h>
39 //=================================================================================================
40 FeaturesPlugin_NormalToFace::FeaturesPlugin_NormalToFace()
44 //=================================================================================================
45 void FeaturesPlugin_NormalToFace::initAttributes()
47 // attribute for object selected
48 data()->addAttribute(FACE_SELECTED_ID(), ModelAPI_AttributeSelection::typeId());
49 data()->addAttribute(VERTEX_SELECTED_ID(), ModelAPI_AttributeSelection::typeId());
51 // attributes for result message and values
52 data()->addAttribute(VERTEX_OPTION_ID(), ModelAPI_AttributeString::typeId());
54 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), VERTEX_SELECTED_ID());
57 //=================================================================================================
58 void FeaturesPlugin_NormalToFace::attributeChanged(const std::string& /*theID*/)
62 //=================================================================================================
63 void FeaturesPlugin_NormalToFace::execute()
66 AttributeSelectionPtr aSelectionFace = selection(FACE_SELECTED_ID());
67 AttributeSelectionPtr aSelectionPoint = selection(VERTEX_SELECTED_ID());
70 GeomShapePtr aShapePoint;
71 if (!string(VERTEX_OPTION_ID())->value().empty()) {
72 if (aSelectionPoint && aSelectionPoint->isInitialized()) {
73 aShapePoint = aSelectionPoint->value();
74 if (!aShapePoint && aSelectionPoint->context())
75 aShapePoint = aSelectionPoint->context()->shape();
79 if (aSelectionFace && aSelectionFace->isInitialized()) {
80 aShape = aSelectionFace->value();
81 if (!aShape && aSelectionFace->context())
82 aShape = aSelectionFace->context()->shape();
87 std::shared_ptr<GeomAPI_Edge> theNormal(new GeomAPI_Edge);
88 if (!GeomAlgoAPI_NormalToFace::normal(aShape,
92 setError("Error in bounding box calculation :" + aError);
95 std::shared_ptr<GeomAPI_Pnt> aPnt = theNormal->lastPoint();
96 if (theNormal.get()) {
97 if (theNormal->isLine()) {
98 theDir = theNormal->line()->direction();
101 aPnt->translate(theDir, 100);
103 std::shared_ptr<GeomAPI_Edge> anEdge =
104 GeomAlgoAPI_EdgeBuilder::line(theNormal->firstPoint(),
107 ResultConstructionPtr aConstr = document()->createConstruction(data());
108 aConstr->setInfinite(true);
109 aConstr->setShape(anEdge);