1 // Name : SketchAPI_Translation.cpp
5 // 16/06/16 - Sergey POKHODENKO - Creation of the file
7 //--------------------------------------------------------------------------------------
8 #include "SketchAPI_Translation.h"
9 #include <SketchAPI_SketchEntity.h>
10 //--------------------------------------------------------------------------------------
11 #include <ModelHighAPI_Dumper.h>
12 #include <ModelHighAPI_Tools.h>
14 #include <SketchPlugin_SketchEntity.h>
15 //--------------------------------------------------------------------------------------
16 SketchAPI_Translation::SketchAPI_Translation(
17 const std::shared_ptr<ModelAPI_Feature> & theFeature)
18 : ModelHighAPI_Interface(theFeature)
23 SketchAPI_Translation::SketchAPI_Translation(
24 const std::shared_ptr<ModelAPI_Feature> & theFeature,
25 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
26 const ModelHighAPI_RefAttr & thePoint1,
27 const ModelHighAPI_RefAttr & thePoint2,
28 const ModelHighAPI_Integer & theNumberOfObjects,
30 : ModelHighAPI_Interface(theFeature)
33 fillAttribute(theObjects, translationList());
34 fillAttribute(thePoint1, startPoint());
35 fillAttribute(thePoint2, endPoint());
36 fillAttribute(theNumberOfObjects, numberOfObjects());
37 fillAttribute(theFullValue ? "FullValue" : "SingleValue", valueType());
43 SketchAPI_Translation::~SketchAPI_Translation()
48 std::list<std::shared_ptr<ModelHighAPI_Interface> > SketchAPI_Translation::translated() const
50 std::list<ObjectPtr> aList = translatedObjects()->list();
51 // remove all initial features
52 std::list<FeaturePtr> anIntermediate;
53 std::list<ObjectPtr>::const_iterator anIt = aList.begin();
54 for (; anIt != aList.end(); ++anIt) {
55 FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
56 AttributeBooleanPtr isCopy = aFeature->boolean(SketchPlugin_SketchEntity::COPY_ID());
57 if (isCopy.get() && isCopy->value())
58 anIntermediate.push_back(aFeature);
60 return SketchAPI_SketchEntity::wrap(anIntermediate);
63 //--------------------------------------------------------------------------------------
65 void SketchAPI_Translation::dump(ModelHighAPI_Dumper& theDumper) const
67 FeaturePtr aBase = feature();
68 const std::string& aSketchName = theDumper.parentName(aBase);
70 AttributeRefListPtr aTransObjects = translationList();
71 AttributeRefAttrPtr aStart = startPoint();
72 AttributeRefAttrPtr aEnd = endPoint();
73 AttributeIntegerPtr aNbCopies = numberOfObjects();
74 bool isFullValue = valueType()->value() != "SingleValue";
76 theDumper << aBase << " = " << aSketchName << ".addTranslation("
77 << aTransObjects << ", " << aStart << ", " << aEnd << ", " << aNbCopies;
79 theDumper << ", " << isFullValue;
80 theDumper << ")" << std::endl;
82 // Dump variables for a list of translated features
84 std::list<std::shared_ptr<ModelHighAPI_Interface> > aList = translated();
85 std::list<std::shared_ptr<ModelHighAPI_Interface> >::const_iterator anIt = aList.begin();
86 for (; anIt != aList.end(); ++anIt) {
87 if (anIt != aList.begin())
89 theDumper << theDumper.name((*anIt)->feature(), false);
91 theDumper << "] = " << theDumper.name(aBase) << ".translated()" << std::endl;