1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2 // Name : SketchAPI_Rotation.cpp
6 // 16/06/16 - Sergey POKHODENKO - Creation of the file
8 //--------------------------------------------------------------------------------------
9 #include "SketchAPI_Rotation.h"
10 #include <SketchAPI_SketchEntity.h>
11 //--------------------------------------------------------------------------------------
12 #include <ModelHighAPI_Dumper.h>
13 #include <ModelHighAPI_Tools.h>
15 #include <SketchPlugin_SketchEntity.h>
16 //--------------------------------------------------------------------------------------
17 SketchAPI_Rotation::SketchAPI_Rotation(
18 const std::shared_ptr<ModelAPI_Feature> & theFeature)
19 : ModelHighAPI_Interface(theFeature)
24 SketchAPI_Rotation::SketchAPI_Rotation(
25 const std::shared_ptr<ModelAPI_Feature> & theFeature,
26 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
27 const ModelHighAPI_RefAttr & theCenter,
28 const ModelHighAPI_Double & theAngle,
29 const ModelHighAPI_Integer & theNumberOfObjects,
31 : ModelHighAPI_Interface(theFeature)
34 fillAttribute(theObjects, rotationList());
35 fillAttribute(theCenter, center());
36 fillAttribute(theAngle, angle());
37 fillAttribute(theNumberOfObjects, numberOfObjects());
38 fillAttribute(theFullValue ? "FullAngle" : "SingleAngle", valueType());
44 SketchAPI_Rotation::~SketchAPI_Rotation()
49 std::list<std::shared_ptr<SketchAPI_SketchEntity> > SketchAPI_Rotation::rotated() const
51 std::list<ObjectPtr> aList = rotatedObjects()->list();
52 // remove all initial features
53 std::list<FeaturePtr> anIntermediate;
54 std::list<ObjectPtr>::const_iterator anIt = aList.begin();
55 for (; anIt != aList.end(); ++anIt) {
56 FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
57 AttributeBooleanPtr isCopy = aFeature->boolean(SketchPlugin_SketchEntity::COPY_ID());
58 if (isCopy.get() && isCopy->value())
59 anIntermediate.push_back(aFeature);
61 return SketchAPI_SketchEntity::wrap(anIntermediate);
64 //--------------------------------------------------------------------------------------
66 void SketchAPI_Rotation::dump(ModelHighAPI_Dumper& theDumper) const
68 FeaturePtr aBase = feature();
69 const std::string& aSketchName = theDumper.parentName(aBase);
71 AttributeRefListPtr aRotObjects = rotationList();
72 AttributeRefAttrPtr aCenter = center();
73 AttributeDoublePtr anAngle = angle();
74 AttributeIntegerPtr aNbCopies = numberOfObjects();
75 bool isFullValue = valueType()->value() != "SingleAngle";
77 theDumper << aBase << " = " << aSketchName << ".addRotation("
78 << aRotObjects << ", " << aCenter << ", " << anAngle << ", " << aNbCopies;
80 theDumper << ", " << isFullValue;
81 theDumper << ")" << std::endl;
83 // Dump variables for a list of rotated features
85 std::list<std::shared_ptr<SketchAPI_SketchEntity> > aList = rotated();
86 std::list<std::shared_ptr<SketchAPI_SketchEntity> >::const_iterator anIt = aList.begin();
87 for (; anIt != aList.end(); ++anIt) {
88 if (anIt != aList.begin())
90 theDumper << theDumper.name((*anIt)->feature(), false);
92 theDumper << "] = " << theDumper.name(aBase) << ".rotated()" << std::endl;
94 // Set necessary "auxiliary" flag for rotated features
95 // (flag is set if it differs to base entity)
96 std::list<ObjectPtr> aRotList = aRotObjects->list();
97 std::list<ObjectPtr>::const_iterator aRIt = aRotList.begin();
99 for (; aRIt != aRotList.end(); ++aRIt) {
100 FeaturePtr aFeature = ModelAPI_Feature::feature(*aRIt);
103 bool aBaseAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
105 for (int i = 1; i < aNbCopies->value(); ++i, ++anIt) {
106 aFeature = (*anIt)->feature();
107 bool aFeatAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
108 if (aFeatAux != aBaseAux)
109 theDumper << theDumper.name((*anIt)->feature(), false)
110 << ".setAuxiliary(" << aFeatAux << ")" <<std::endl;