1 // Copyright (C) 2014-2017 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 "SketchAPI_Rotation.h"
22 #include <SketchAPI_SketchEntity.h>
23 //--------------------------------------------------------------------------------------
24 #include <ModelHighAPI_Dumper.h>
25 #include <ModelHighAPI_Tools.h>
27 #include <SketchPlugin_SketchEntity.h>
28 //--------------------------------------------------------------------------------------
29 SketchAPI_Rotation::SketchAPI_Rotation(
30 const std::shared_ptr<ModelAPI_Feature> & theFeature)
31 : ModelHighAPI_Interface(theFeature)
36 SketchAPI_Rotation::SketchAPI_Rotation(
37 const std::shared_ptr<ModelAPI_Feature> & theFeature,
38 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
39 const ModelHighAPI_RefAttr & theCenter,
40 const ModelHighAPI_Double & theAngle,
41 const ModelHighAPI_Integer & theNumberOfObjects,
44 : ModelHighAPI_Interface(theFeature)
47 fillAttribute(theObjects, rotationList());
48 fillAttribute(theCenter, center());
49 fillAttribute(theFullValue ? "FullAngle" : "SingleAngle", valueType());
50 fillAttribute(theAngle, angle());
51 fillAttribute(theReversed, reversed());
52 fillAttribute(theNumberOfObjects, numberOfObjects());
58 SketchAPI_Rotation::~SketchAPI_Rotation()
63 std::list<std::shared_ptr<SketchAPI_SketchEntity> > SketchAPI_Rotation::rotated() const
65 std::list<ObjectPtr> aList = rotatedObjects()->list();
66 // remove all initial features
67 std::list<FeaturePtr> anIntermediate;
68 std::list<ObjectPtr>::const_iterator anIt = aList.begin();
69 for (; anIt != aList.end(); ++anIt) {
70 FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
71 AttributeBooleanPtr isCopy = aFeature->boolean(SketchPlugin_SketchEntity::COPY_ID());
72 if (isCopy.get() && isCopy->value())
73 anIntermediate.push_back(aFeature);
75 return SketchAPI_SketchEntity::wrap(anIntermediate);
78 //--------------------------------------------------------------------------------------
80 void SketchAPI_Rotation::dump(ModelHighAPI_Dumper& theDumper) const
82 FeaturePtr aBase = feature();
83 const std::string& aSketchName = theDumper.parentName(aBase);
85 AttributeRefListPtr aRotObjects = rotationList();
86 AttributeRefAttrPtr aCenter = center();
87 AttributeDoublePtr anAngle = angle();
88 AttributeIntegerPtr aNbCopies = numberOfObjects();
89 bool isFullValue = valueType()->value() != "SingleAngle";
90 bool isReversed = reversed()->value();
92 // Check all attributes are already dumped. If not, store the constraint as postponed.
93 if (!theDumper.isDumped(aCenter) || !theDumper.isDumped(aRotObjects)) {
94 theDumper.postpone(aBase);
98 theDumper << aBase << " = " << aSketchName << ".addRotation("
99 << aRotObjects << ", " << aCenter << ", " << anAngle << ", " << aNbCopies;
100 if (isFullValue || isReversed)
102 theDumper << ", " << isFullValue;
104 theDumper << ", " << isReversed;
106 theDumper << ")" << std::endl;
108 // Dump variables for a list of rotated features
110 std::list<std::shared_ptr<SketchAPI_SketchEntity> > aList = rotated();
111 std::list<std::shared_ptr<SketchAPI_SketchEntity> >::const_iterator anIt = aList.begin();
112 for (; anIt != aList.end(); ++anIt) {
113 if (anIt != aList.begin())
115 theDumper << (*anIt)->feature();
117 theDumper << "] = " << theDumper.name(aBase) << ".rotated()" << std::endl;
119 // Set necessary "auxiliary" flag for rotated features
120 // (flag is set if it differs to base entity)
121 std::list<ObjectPtr> aRotList = aRotObjects->list();
122 std::list<ObjectPtr>::const_iterator aRIt = aRotList.begin();
123 anIt = aList.begin();
124 for (; aRIt != aRotList.end(); ++aRIt) {
125 FeaturePtr aFeature = ModelAPI_Feature::feature(*aRIt);
128 bool aBaseAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
130 for (int i = 1; i < aNbCopies->value(); ++i, ++anIt) {
131 aFeature = (*anIt)->feature();
132 bool aFeatAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
133 if (aFeatAux != aBaseAux)
134 theDumper << theDumper.name((*anIt)->feature(), false)
135 << ".setAuxiliary(" << aFeatAux << ")" <<std::endl;