]> SALOME platform Git repositories - modules/shaper.git/blob - src/FeaturesPlugin/FeaturesPlugin_ExtrusionBoolean.cpp
Salome HOME
Improvement #615: Widgets position in Extrusion and Rotation features must be changed.
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_ExtrusionBoolean.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        FeaturesPlugin_ExtrusionBoolean.h
4 // Created:     11 June 2015
5 // Author:      Dmitry Bobylev
6
7 #include <FeaturesPlugin_ExtrusionBoolean.h>
8
9 #include <ModelAPI_AttributeDouble.h>
10 #include <ModelAPI_AttributeSelection.h>
11 #include <ModelAPI_AttributeString.h>
12 #include <ModelAPI_Session.h>
13 #include <ModelAPI_Validator.h>
14
15 #include <GeomAlgoAPI_Prism.h>
16
17 //=================================================================================================
18 void FeaturesPlugin_ExtrusionBoolean::initMakeSolidsAttributes()
19 {
20   data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
21
22   data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
23   data()->addAttribute(TO_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
24
25   data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
26   data()->addAttribute(FROM_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
27
28   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID());
29   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID());
30 }
31
32 //=================================================================================================
33 ListOfShape FeaturesPlugin_ExtrusionBoolean::MakeSolids(const ListOfShape& theFaces)
34 {
35   // Getting extrusion sizes.
36   double aFromSize = real(FROM_SIZE_ID())->value();
37   double aToSize = real(TO_SIZE_ID())->value();
38
39   // Getting extrusion bounding planes.
40   std::shared_ptr<GeomAPI_Shape> aFromShape;
41   std::shared_ptr<GeomAPI_Shape> aToShape;
42
43   if(string(CREATION_METHOD())->value() == "ByPlanesAndOffsets") {
44     std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = selection(FROM_OBJECT_ID());
45     if(anObjRef.get() != NULL) {
46       aFromShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
47       if(aFromShape.get() == NULL && anObjRef->context().get() != NULL) {
48         aFromShape = anObjRef->context()->shape();
49       }
50     }
51     anObjRef = selection(TO_OBJECT_ID());
52     if(anObjRef.get() != NULL) {
53       aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
54       if(aToShape.get() == NULL && anObjRef->context().get() != NULL) {
55         aToShape =  anObjRef->context()->shape();
56       }
57     }
58   }
59
60   // Extrude faces.
61   ListOfShape anExtrusionList;
62   for(ListOfShape::const_iterator aFacesIt = theFaces.begin(); aFacesIt != theFaces.end(); aFacesIt++) {
63     std::shared_ptr<GeomAPI_Shape> aBaseShape = *aFacesIt;
64     GeomAlgoAPI_Prism aPrismAlgo(aBaseShape, aToShape, aToSize, aFromShape, aFromSize);
65
66     // Checking that the algorithm worked properly.
67     if(!aPrismAlgo.isDone() || aPrismAlgo.shape()->isNull() || !aPrismAlgo.isValid()) {
68       setError("Extrusion algorithm failed");
69       return ListOfShape();
70     }
71     anExtrusionList.push_back(aPrismAlgo.shape());
72   }
73
74   return anExtrusionList;
75 }