1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: SketchPlugin_ConstraintFillet.cpp
4 // Created: 19 Mar 2015
5 // Author: Artem ZHIDKOV
7 #include "SketchPlugin_ConstraintFillet.h"
9 #include <ModelAPI_AttributeDouble.h>
10 #include <ModelAPI_Data.h>
11 #include <ModelAPI_ResultConstruction.h>
12 #include <ModelAPI_AttributeRefAttr.h>
13 #include <ModelAPI_AttributeRefList.h>
14 #include <ModelAPI_Session.h>
16 #include <SketchPlugin_Arc.h>
17 #include <SketchPlugin_Sketch.h>
19 #include <SketcherPrs_Factory.h>
21 #include <Config_PropManager.h>
23 SketchPlugin_ConstraintFillet::SketchPlugin_ConstraintFillet()
27 void SketchPlugin_ConstraintFillet::initAttributes()
29 data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::type());
30 data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
31 data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::type());
32 data()->addAttribute(SketchPlugin_Constraint::ENTITY_C(), ModelAPI_AttributeRefList::type());
33 // initialize attribute not applicable for user
34 data()->attribute(SketchPlugin_Constraint::ENTITY_C())->setInitialized();
37 void SketchPlugin_ConstraintFillet::execute()
39 std::shared_ptr<ModelAPI_Data> aData = data();
40 // Check the base objects are initialized
41 AttributeRefAttrPtr aBaseA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
42 aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
43 AttributeRefAttrPtr aBaseB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
44 aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
45 if (!aBaseA->isInitialized() || !aBaseB->isInitialized() ||
46 !aBaseA->isObject() || !aBaseB->isObject())
48 // Check the fillet shapes is not initialized yet
49 AttributeRefListPtr aRefListOfFillet = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
50 aData->attribute(SketchPlugin_Constraint::ENTITY_C()));
51 if (aRefListOfFillet->size() > 0)
53 // Obtain features for the base objects
54 FeaturePtr aFeatureA, aFeatureB;
55 ResultConstructionPtr aRC =
56 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aBaseA->object());
57 if (aRC) aFeatureA = aRC->document()->feature(aRC);
58 aRC = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aBaseB->object());
59 if (aRC) aFeatureB = aRC->document()->feature(aRC);
60 if (!aFeatureA || !aFeatureB)
63 // Create list of objects composing a fillet
65 FeaturePtr aNewFeature = sketch()->addFeature(aFeatureA->getKind());
66 aFeatureA->data()->copyTo(aNewFeature->data());
67 aRefListOfFillet->append(aNewFeature);
69 aNewFeature = sketch()->addFeature(aFeatureB->getKind());
70 aFeatureB->data()->copyTo(aNewFeature->data());
71 aRefListOfFillet->append(aNewFeature);
72 // create filleting arc
73 aNewFeature = sketch()->addFeature(SketchPlugin_Arc::ID());
74 aNewFeature->attribute(SketchPlugin_Arc::CENTER_ID())->setInitialized();
75 aNewFeature->attribute(SketchPlugin_Arc::START_ID())->setInitialized();
76 aNewFeature->attribute(SketchPlugin_Arc::END_ID())->setInitialized();
77 aRefListOfFillet->append(aNewFeature);
78 aRefListOfFillet->setInitialized();
81 AISObjectPtr SketchPlugin_ConstraintFillet::getAISObject(AISObjectPtr thePrevious)
86 AISObjectPtr anAIS = thePrevious;
87 /// TODO: Equal constraint presentation should be put here