1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2 // Name : SketchAPI_Translation.cpp
6 // 16/06/16 - Sergey POKHODENKO - Creation of the file
8 //--------------------------------------------------------------------------------------
9 #include "SketchAPI_Translation.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_Translation::SketchAPI_Translation(
18 const std::shared_ptr<ModelAPI_Feature> & theFeature)
19 : ModelHighAPI_Interface(theFeature)
24 SketchAPI_Translation::SketchAPI_Translation(
25 const std::shared_ptr<ModelAPI_Feature> & theFeature,
26 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
27 const ModelHighAPI_RefAttr & thePoint1,
28 const ModelHighAPI_RefAttr & thePoint2,
29 const ModelHighAPI_Integer & theNumberOfObjects,
31 : ModelHighAPI_Interface(theFeature)
34 fillAttribute(theObjects, translationList());
35 fillAttribute(thePoint1, startPoint());
36 fillAttribute(thePoint2, endPoint());
37 fillAttribute(theNumberOfObjects, numberOfObjects());
38 fillAttribute(theFullValue ? "FullValue" : "SingleValue", valueType());
44 SketchAPI_Translation::~SketchAPI_Translation()
49 std::list<std::shared_ptr<SketchAPI_SketchEntity> > SketchAPI_Translation::translated() const
51 std::list<ObjectPtr> aList = translatedObjects()->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_Translation::dump(ModelHighAPI_Dumper& theDumper) const
68 FeaturePtr aBase = feature();
69 const std::string& aSketchName = theDumper.parentName(aBase);
71 AttributeRefListPtr aTransObjects = translationList();
72 AttributeRefAttrPtr aStart = startPoint();
73 AttributeRefAttrPtr aEnd = endPoint();
74 AttributeIntegerPtr aNbCopies = numberOfObjects();
75 bool isFullValue = valueType()->value() != "SingleValue";
77 theDumper << aBase << " = " << aSketchName << ".addTranslation("
78 << aTransObjects << ", " << aStart << ", " << aEnd << ", " << aNbCopies;
80 theDumper << ", " << isFullValue;
81 theDumper << ")" << std::endl;
83 // Dump variables for a list of translated features
85 std::list<std::shared_ptr<SketchAPI_SketchEntity> > aList = translated();
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) << ".translated()" << std::endl;
94 // Set necessary "auxiliary" flag for translated features
95 // (flag is set if it differs to base entity)
96 std::list<ObjectPtr> aTransList = aTransObjects->list();
97 std::list<ObjectPtr>::const_iterator aTrIt = aTransList.begin();
99 for (; aTrIt != aTransList.end(); ++aTrIt) {
100 FeaturePtr aFeature = ModelAPI_Feature::feature(*aTrIt);
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;