1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2 // Name : SketchAPI_Mirror.cpp
6 // 16/06/16 - Sergey POKHODENKO - Creation of the file
8 //--------------------------------------------------------------------------------------
9 #include "SketchAPI_Mirror.h"
10 #include <SketchAPI_SketchEntity.h>
11 //--------------------------------------------------------------------------------------
12 #include <ModelHighAPI_Dumper.h>
13 #include <ModelHighAPI_Selection.h>
14 #include <ModelHighAPI_Tools.h>
15 //--------------------------------------------------------------------------------------
16 SketchAPI_Mirror::SketchAPI_Mirror(
17 const std::shared_ptr<ModelAPI_Feature> & theFeature)
18 : ModelHighAPI_Interface(theFeature)
23 SketchAPI_Mirror::SketchAPI_Mirror(
24 const std::shared_ptr<ModelAPI_Feature> & theFeature,
25 const ModelHighAPI_RefAttr & theMirrorLine,
26 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
27 : ModelHighAPI_Interface(theFeature)
30 fillAttribute(theMirrorLine, mirrorLine());
31 fillAttribute(theObjects, mirrorList());
37 SketchAPI_Mirror::~SketchAPI_Mirror()
42 std::list<std::shared_ptr<SketchAPI_SketchEntity> > SketchAPI_Mirror::mirrored() const
44 std::list<ObjectPtr> aList = mirroredObjects()->list();
45 std::list<FeaturePtr> anIntermediate;
46 std::list<ObjectPtr>::const_iterator anIt = aList.begin();
47 for (; anIt != aList.end(); ++anIt) {
48 FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
49 anIntermediate.push_back(aFeature);
51 return SketchAPI_SketchEntity::wrap(anIntermediate);
54 //--------------------------------------------------------------------------------------
56 void SketchAPI_Mirror::dump(ModelHighAPI_Dumper& theDumper) const
58 FeaturePtr aBase = feature();
59 const std::string& aSketchName = theDumper.parentName(aBase);
61 AttributeRefAttrPtr aMirrorLine = mirrorLine();
62 AttributeRefListPtr aMirrorObjects = mirrorList();
63 theDumper << aBase << " = " << aSketchName << ".addMirror(" << aMirrorLine << ", "
64 << aMirrorObjects << ")" << std::endl;
66 // Dump variables for a list of mirrored features
68 std::list<std::shared_ptr<SketchAPI_SketchEntity> > aList = mirrored();
69 std::list<std::shared_ptr<SketchAPI_SketchEntity> >::const_iterator anIt = aList.begin();
70 for (; anIt != aList.end(); ++anIt) {
71 if (anIt != aList.begin())
73 theDumper << theDumper.name((*anIt)->feature(), false);
75 theDumper << "] = " << theDumper.name(aBase) << ".mirrored()" << std::endl;
77 // Set necessary "auxiliary" flag for mirrored features
78 // (flag is set if it differs to base entity)
79 std::list<ObjectPtr> aMirList = aMirrorObjects->list();
80 std::list<ObjectPtr>::const_iterator aMIt = aMirList.begin();
81 for (anIt = aList.begin(); aMIt != aMirList.end(); ++aMIt, ++anIt) {
82 FeaturePtr aFeature = ModelAPI_Feature::feature(*aMIt);
85 bool aBaseAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
87 aFeature = (*anIt)->feature();
88 bool aFeatAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
89 if (aFeatAux != aBaseAux)
90 theDumper << theDumper.name((*anIt)->feature(), false)
91 << ".setAuxiliary(" << aFeatAux << ")" <<std::endl;