Salome HOME
Set icons for revolution operations
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Placement.cpp
index b9b567f41de06280a519132846878e3ee49977b5..d069858d45e3c528412516c8e6b3c73911cc7f88 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
 // File:        FeaturesPlugin_Placement.cpp
 // Created:     2 Dec 2014
 // Author:      Artem ZHIDKOV
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeSelectionList.h>
 
+#include <GeomAPI_Edge.h>
 #include <GeomAPI_Face.h>
 #include <GeomAPI_Pln.h>
 #include <GeomAlgoAPI_Placement.h>
 
+#define _MODIFIEDF_TAG 1
+#define _MODIFIEDE_TAG 2
+#define _MODIFIEDV_TAG 3
+#define _FACE 4
 FeaturesPlugin_Placement::FeaturesPlugin_Placement()
 {
 }
 
 void FeaturesPlugin_Placement::initAttributes()
 {
-  data()->addAttribute(FeaturesPlugin_Placement::BASE_FACE_ID(), ModelAPI_AttributeSelection::type());
-  data()->addAttribute(FeaturesPlugin_Placement::ATTRACT_FACE_ID(), ModelAPI_AttributeSelection::type());
+  /* Modification for specification of 1.3.0
+  AttributeSelectionListPtr aSelection = 
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->addAttribute(
+    FeaturesPlugin_Placement::LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
+  // extrusion works with faces always
+  aSelection->setSelectionType("SOLID");
+  */
+  data()->addAttribute(FeaturesPlugin_Placement::BASE_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(FeaturesPlugin_Placement::ATTRACT_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(FeaturesPlugin_Placement::REVERSE_ID(), ModelAPI_AttributeBoolean::typeId());
+  data()->addAttribute(FeaturesPlugin_Placement::CENTERING_ID(), ModelAPI_AttributeBoolean::typeId());
 }
 
 void FeaturesPlugin_Placement::execute()
 {
   // Verify the base face
-  std::shared_ptr<ModelAPI_AttributeSelection> aFaceRef = std::dynamic_pointer_cast<
-    ModelAPI_AttributeSelection>(data()->attribute(FeaturesPlugin_Placement::BASE_FACE_ID()));
-  if (!aFaceRef)
+  std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = std::dynamic_pointer_cast<
+    ModelAPI_AttributeSelection>(data()->attribute(FeaturesPlugin_Placement::BASE_OBJECT_ID()));
+  if (!anObjRef)
     return;
 
-  std::shared_ptr<GeomAPI_Shape> aBaseFace = 
-    std::dynamic_pointer_cast<GeomAPI_Shape>(aFaceRef->value());
-  if (!aBaseFace)
+  std::shared_ptr<GeomAPI_Shape> aBaseShape = 
+    std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
+  if (!aBaseShape)
     return;
 
-  std::shared_ptr<GeomAPI_Shape> aBaseFaceContext;
-  ResultPtr aContextRes = aFaceRef->context();
+  std::shared_ptr<GeomAPI_Shape> aBaseObject;
+  ResultPtr aContextRes = anObjRef->context();
   if (aContextRes) {
     if (aContextRes->groupName() == ModelAPI_ResultBody::group())
-      aBaseFaceContext = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContextRes)->shape();
+      aBaseObject = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContextRes)->shape();
     else if (aContextRes->groupName() == ModelAPI_ResultConstruction::group())
-      aBaseFaceContext = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContextRes)->shape();
+      aBaseObject = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContextRes)->shape();
   }
-  if (!aBaseFaceContext) {
+  if (!aBaseObject) {
     static const std::string aContextError = "The selection context is bad";
     setError(aContextError);
     return;
   }
 
   // Verify the attractive face
-  aFaceRef = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(
-      data()->attribute(FeaturesPlugin_Placement::ATTRACT_FACE_ID()));
+  anObjRef = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(
+      data()->attribute(FeaturesPlugin_Placement::ATTRACT_OBJECT_ID()));
 
-  std::shared_ptr<GeomAPI_Shape> anAttractiveFace = 
-    std::dynamic_pointer_cast<GeomAPI_Shape>(aFaceRef->value());
-  if (!anAttractiveFace)
+  std::shared_ptr<GeomAPI_Shape> aSlaveShape = 
+    std::dynamic_pointer_cast<GeomAPI_Shape>(anObjRef->value());
+  if (!aSlaveShape)
     return;
 
-  std::shared_ptr<GeomAPI_Shape> anAttractiveFaceContext;
-  aContextRes = aFaceRef->context();
+  std::shared_ptr<GeomAPI_Shape> aSlaveObject;
+  aContextRes = anObjRef->context();
   if (aContextRes) {
     if (aContextRes->groupName() == ModelAPI_ResultBody::group())
-      anAttractiveFaceContext = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContextRes)->shape();
+      aSlaveObject = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aContextRes)->shape();
     else if (aContextRes->groupName() == ModelAPI_ResultConstruction::group())
-      anAttractiveFaceContext = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContextRes)->shape();
+      aSlaveObject = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContextRes)->shape();
   }
-  if (!anAttractiveFaceContext) {
+  if (!aSlaveObject) {
     static const std::string aContextError = "The selection context is bad";
     setError(aContextError);
     return;
   }
 
-  // Verify faces planarity
-  std::shared_ptr<GeomAPI_Face> aBaseFace1(new GeomAPI_Face(aBaseFace));
-  std::shared_ptr<GeomAPI_Face> anAttractFace1(new GeomAPI_Face(anAttractiveFace));
-  if (!aBaseFace1->isPlanar() || !anAttractFace1->isPlanar()) {
-    static const std::string aPlanarityError = "One of selected face is not planar";
-    setError(aPlanarityError);
-    return;
+  // Verify planarity of faces and linearity of edges
+  std::shared_ptr<GeomAPI_Shape> aShapes[2] = {aBaseShape, aSlaveShape};
+  for (int i = 0; i < 2; i++) {
+    if (aShapes[i]->isFace()) {
+      std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aShapes[i]));
+      if (!aFace->isPlanar()) {
+        static const std::string aPlanarityError = "One of selected faces is not planar";
+        setError(aPlanarityError);
+        return;
+      }
+    }
+    else if (aShapes[i]->isEdge()) {
+      std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aShapes[i]));
+      if (!anEdge->isLine()) {
+        static const std::string aLinearityError = "One of selected endges is not linear";
+        setError(aLinearityError);
+        return;
+      }
+    }
   }
 
-  std::shared_ptr<GeomAPI_Pln> aBasePlane = aBaseFace1->getPlane();
-  std::shared_ptr<GeomAPI_Pln> anAttractivePlane = anAttractFace1->getPlane();
+  // Flags of the Placement
+  AttributeBooleanPtr aBoolAttr = std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(
+      data()->attribute(FeaturesPlugin_Placement::REVERSE_ID()));
+  bool isReverse = aBoolAttr->value();
+  aBoolAttr = std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(
+      data()->attribute(FeaturesPlugin_Placement::CENTERING_ID()));
+  bool isCentering = aBoolAttr->value();
 
   std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
-  GeomAlgoAPI_Placement aFeature(anAttractiveFaceContext, anAttractivePlane, aBasePlane);
+  GeomAlgoAPI_Placement aFeature(aSlaveObject, aBaseObject, aSlaveShape, aBaseShape, isReverse, isCentering);
   if(!aFeature.isDone()) {
     static const std::string aFeatureError = "Placement algorithm failed";
     setError(aFeatureError);
@@ -104,7 +139,7 @@ void FeaturesPlugin_Placement::execute()
     return;
   }  
   //LoadNamingDS
-  LoadNamingDS(aFeature, aResultBody, anAttractiveFace, anAttractiveFaceContext);
+  LoadNamingDS(aFeature, aResultBody, aSlaveObject);
 
   setResult(aResultBody);
 }
@@ -113,43 +148,16 @@ void FeaturesPlugin_Placement::execute()
 void FeaturesPlugin_Placement::LoadNamingDS(
     GeomAlgoAPI_Placement& theFeature,
     std::shared_ptr<ModelAPI_ResultBody> theResultBody,
-    std::shared_ptr<GeomAPI_Shape> theBasis,
-    std::shared_ptr<GeomAPI_Shape> theContext)
+    std::shared_ptr<GeomAPI_Shape> theSlaveObject)
 {
-  /// TODO: SZY
-/*
-
   //load result
-  if(theBasis->isEqual(theContext))
-    theResultBody->store(theFeature.shape());
-  else
-    theResultBody->storeGenerated(theContext, theFeature.shape()); 
+  theResultBody->storeModified(theSlaveObject, theFeature.shape()); // the initial Slave, the resulting Slave
 
   GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape();
   theFeature.mapOfShapes(*aSubShapes);
+  
+    // put modifed faces in DF
+  std::string aModName = "Modified";
+  theResultBody->loadAndOrientModifiedShapes(theFeature.makeShape(), theSlaveObject, _FACE, _MODIFIEDF_TAG, aModName, *aSubShapes); 
 
-    //Insert lateral face : Face from Edge
-  theResultBody->loadAndOrientGeneratedShapes(theFeature.makeShape(), theBasis, EDGE,_LATERAL_TAG, *aSubShapes);
-
-  //Insert bottom face
-  std::shared_ptr<GeomAPI_Shape> aBottomFace = theFeature.firstShape();  
-  if (!aBottomFace->isNull()) {
-       if (aSubShapes->isBound(aBottomFace)) {  
-               aBottomFace = aSubShapes->find(aBottomFace);            
-    }    
-    theResultBody->generated(aBottomFace, _FIRST_TAG);
-  }
-
-
-
-  //Insert top face
-  std::shared_ptr<GeomAPI_Shape> aTopFace = theFeature.lastShape();
-  if (!aTopFace->isNull()) {
-    if (aSubShapes->isBound(aTopFace)) {        
-      aTopFace = aSubShapes->find(aTopFace);   
-    }
-    theResultBody->generated(aTopFace, _LAST_TAG);
-  }
-
-*/
 }