1 // Copyright (C) 2014-2019 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 "SketchAPI_Offset.h"
21 #include <SketchAPI_SketchEntity.h>
22 //--------------------------------------------------------------------------------------
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Selection.h>
25 #include <ModelHighAPI_Tools.h>
27 //--------------------------------------------------------------------------------------
28 SketchAPI_Offset::SketchAPI_Offset (const std::shared_ptr<ModelAPI_Feature> & theFeature)
29 : ModelHighAPI_Interface(theFeature)
34 SketchAPI_Offset::SketchAPI_Offset (const std::shared_ptr<ModelAPI_Feature> & theFeature,
35 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
36 const ModelHighAPI_Double & theOffsetValue,
38 : ModelHighAPI_Interface(theFeature)
41 fillAttribute(theObjects, edgesList());
42 fillAttribute(theOffsetValue, value());
43 fillAttribute(theIsReversed, reversed());
49 SketchAPI_Offset::~SketchAPI_Offset()
53 std::list<std::shared_ptr<SketchAPI_SketchEntity> > SketchAPI_Offset::offset() const
55 std::list<ObjectPtr> aList = feature()->reflist(SketchPlugin_Constraint::ENTITY_B())->list();
56 std::list<FeaturePtr> anIntermediate;
57 std::list<ObjectPtr>::const_iterator anIt = aList.begin();
58 for (; anIt != aList.end(); ++anIt) {
59 FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
60 anIntermediate.push_back(aFeature);
62 return SketchAPI_SketchEntity::wrap(anIntermediate);
65 //--------------------------------------------------------------------------------------
67 void SketchAPI_Offset::dump (ModelHighAPI_Dumper& theDumper) const
69 FeaturePtr aBase = feature();
70 const std::string& aSketchName = theDumper.parentName(aBase);
72 AttributeRefListPtr aOffsetObjects = edgesList();
73 AttributeDoublePtr aValue = value();
74 AttributeBooleanPtr aReversed = reversed();
76 // Check all attributes are already dumped. If not, store the feature as postponed.
77 if (!theDumper.isDumped(aOffsetObjects)) {
78 theDumper.postpone(aBase);
82 theDumper << aBase << " = " << aSketchName << ".addOffset(" << aOffsetObjects << ", "
83 << aValue << ", " << aReversed << ")" << std::endl;
85 // Dump variables for a list of created features
87 std::list<std::shared_ptr<SketchAPI_SketchEntity> > aList = offset();
88 std::list<std::shared_ptr<SketchAPI_SketchEntity> >::const_iterator anIt = aList.begin();
89 for (; anIt != aList.end(); ++anIt) {
90 if (anIt != aList.begin())
92 theDumper << (*anIt)->feature();
94 theDumper << "] = " << theDumper.name(aBase) << ".offset()" << std::endl;
96 //// // Set necessary "auxiliary" flag for created features
97 //// // (flag is set if it differs to anAux)
98 //// for (anIt = aList.begin(); anIt != aList.end(); ++anIt) {
99 //// FeaturePtr aFeature = (*anIt)->feature();
100 //// bool aFeatAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
101 //// if (aFeatAux != anAux->value())
102 //// theDumper << theDumper.name((*anIt)->feature(), false)
103 //// << ".setAuxiliary(" << aFeatAux << ")" <<std::endl;