Salome HOME
39db5fd96c8f4348f63701d5d1b2e80a5bb47e2d
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Sewing.cpp
1 // Copyright (C) 2014-2023  CEA/DEN, EDF R&D
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 "FeaturesAPI_Sewing.h"
21
22 #include <ModelHighAPI_Double.h>
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Tools.h>
25
26 //==================================================================================================
27 FeaturesAPI_Sewing::FeaturesAPI_Sewing(const std::shared_ptr<ModelAPI_Feature>& theFeature)
28 : ModelHighAPI_Interface(theFeature)
29 {
30   initialize();
31 }
32
33 //==================================================================================================
34 FeaturesAPI_Sewing::FeaturesAPI_Sewing(const std::shared_ptr<ModelAPI_Feature>& theFeature,
35                                        const std::list<ModelHighAPI_Selection>& theMainObjects,
36                                        const ModelHighAPI_Double& theTolerance,
37                                        bool theIsAllowNonManifold/*=false*/,
38                                        bool theIsAlwaysCreateResult/*=true*/)
39 : ModelHighAPI_Interface(theFeature)
40 {
41   if (initialize()) {
42     fillAttribute(theMainObjects, mainObjects());
43     setTolerance(theTolerance);
44     setIsAllowNonManifold(theIsAllowNonManifold);
45     setIsAlwaysCreateResult(theIsAlwaysCreateResult);
46   }
47 }
48
49 //==================================================================================================
50 FeaturesAPI_Sewing::~FeaturesAPI_Sewing()
51 {
52 }
53
54 //==================================================================================================
55 void FeaturesAPI_Sewing::setMainObjects(const std::list<ModelHighAPI_Selection>& theMainObjects)
56 {
57   fillAttribute(theMainObjects, mainObjects());
58   execute();
59 }
60
61 //==================================================================================================
62 void FeaturesAPI_Sewing::setTolerance(const ModelHighAPI_Double& theTolerance)
63 {
64   fillAttribute(theTolerance, tolerance());
65   execute();
66 }
67
68 //==================================================================================================
69 void FeaturesAPI_Sewing::setIsAllowNonManifold(bool theFlag)
70 {
71   fillAttribute(theFlag, isAllowNonManifold());
72   execute();
73 }
74
75 //==================================================================================================
76 void FeaturesAPI_Sewing::setIsAlwaysCreateResult(bool theFlag)
77 {
78   fillAttribute(theFlag, isAlwaysCreateResult());
79   execute();
80 }
81
82 //==================================================================================================
83 void FeaturesAPI_Sewing::dump(ModelHighAPI_Dumper& theDumper) const
84 {
85   FeaturePtr aBase = feature();
86   const std::string& aDocName = theDumper.name(aBase->document());
87
88   AttributeSelectionListPtr anAttrObjects =
89     aBase->selectionList(FeaturesPlugin_Sewing::OBJECTS_LIST_ID());
90   theDumper << aBase << " = model.addSewing(" << aDocName << ", " << anAttrObjects;
91
92   AttributeDoublePtr anAttrTolerance = aBase->real(FeaturesPlugin_Sewing::TOLERANCE_ID());
93   theDumper << ", " << anAttrTolerance;
94
95   AttributeBooleanPtr anAttrAllowNonMFold = aBase->boolean(FeaturesPlugin_Sewing::ALLOW_NON_MANIFOLD_ID());
96   theDumper << ", allowNonManifold = " << anAttrAllowNonMFold;
97
98   AttributeBooleanPtr anAttrAlwaysResult = aBase->boolean(FeaturesPlugin_Sewing::ALWAYS_CREATE_RESULT_ID());
99   theDumper << ", alwaysCreateResult = " << anAttrAlwaysResult;
100
101   theDumper << ")" << std::endl;
102 }
103
104 //==================================================================================================
105 SewingPtr addSewing(const std::shared_ptr<ModelAPI_Document>& thePart,
106                     const std::list<ModelHighAPI_Selection>& theMainObjects,
107                     const ModelHighAPI_Double& theTolerance,
108                     const bool allowNonManifold,
109                     const bool alwaysCreateResult)
110 {
111   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Sewing::ID());
112   SewingPtr aSewing;
113   aSewing.reset(new FeaturesAPI_Sewing(aFeature, theMainObjects, theTolerance, allowNonManifold, alwaysCreateResult));
114   return aSewing;
115 }