Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_ConstraintFillet.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:    SketchPlugin_ConstraintFillet.cpp
4 // Created: 19 Mar 2015
5 // Author:  Artem ZHIDKOV
6
7 #include "SketchPlugin_ConstraintFillet.h"
8
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>
15
16 #include <SketchPlugin_Arc.h>
17 #include <SketchPlugin_Sketch.h>
18
19 #include <SketcherPrs_Factory.h>
20
21 #include <Config_PropManager.h>
22
23 SketchPlugin_ConstraintFillet::SketchPlugin_ConstraintFillet()
24 {
25 }
26
27 void SketchPlugin_ConstraintFillet::initAttributes()
28 {
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();
35 }
36
37 void SketchPlugin_ConstraintFillet::execute()
38 {
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())
47     return;
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)
52     return;
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)
61     return;
62
63   // Create list of objects composing a fillet
64   // copy aFeatureA
65   FeaturePtr aNewFeature = sketch()->addFeature(aFeatureA->getKind());
66   aFeatureA->data()->copyTo(aNewFeature->data());
67   aRefListOfFillet->append(aNewFeature);
68   // copy aFeatureB
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();
79 }
80
81 AISObjectPtr SketchPlugin_ConstraintFillet::getAISObject(AISObjectPtr thePrevious)
82 {
83   if (!sketch())
84     return thePrevious;
85
86   AISObjectPtr anAIS = thePrevious;
87   /// TODO: Equal constraint presentation should be put here
88   return anAIS;
89 }
90
91