]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
feat : AddNode with translation and no swallow
authorNicolas RECHATIN <nicolas.rechatin@cea.fr>
Fri, 2 Jun 2023 10:21:45 +0000 (12:21 +0200)
committerNicolas RECHATIN <nicolas.rechatin@cea.fr>
Fri, 2 Jun 2023 10:21:45 +0000 (12:21 +0200)
src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp
src/ExchangePlugin/ExchangePlugin_ExportRoot.cpp
src/ExchangePlugin/ExchangePlugin_ExportRoot.h
src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.cpp
src/GeomAlgoAPI/GeomAlgoAPI_ROOTExport.h
src/OperaAPI/OperaAPI_AddNode.h
src/OperaPlugin/OperaPlugin_AddNode.cpp
src/OperaPlugin/OperaPlugin_AddNode.h
src/OperaPlugin/addnode_widget.xml
src/OperaPlugin/volume_widget.xml

index 378b2a442a30890de5280bba10cf7f0108e408a6..52cb79909c74afca961d392c06536589b1f83a6f 100644 (file)
@@ -703,8 +703,6 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string &theFileName)
 
     // Handling data
     std::list<std::string> aListOfMedias;
-    std::map<std::wstring, std::string> aListOfVolumes;
-    std::map<std::string, std::vector <std::array<std::string, 2>>> aCopyData;
 
     // Add feature in the file
     std::list<FeaturePtr> aFeatures = document()->allFeatures();
@@ -729,61 +727,35 @@ void ExchangePlugin_ExportFeature::exportROOT(const std::string &theFileName)
         }
         else if (aFeature->getKind() == "Volume")
         {
-            std::map<std::string, std::string> aFeatureDimensions;
-            aFeatureDimensions = ExchangePlugin_ExportRoot::computeVolume(aFeature);
-            std::wstring anObjectName = aFeature->firstResult()->data()->name();
+            std::list<std::map<std::string, std::string>> aFeatureDimensionsList;
+            aFeatureDimensionsList = ExchangePlugin_ExportRoot::computeVolume(aFeature);
+
+            const std::list<ResultPtr> &aResultList = aFeature->results();
+            auto aResIt = aResultList.begin();
 
-            //Filter on already created medias
-            std::list<std::string>::iterator anIter = std::find(aListOfMedias.begin(), aListOfMedias.end(), aFeatureDimensions["medium"]);
-            if (anIter != aListOfMedias.end())
-                anAlgo->buildVolume(anObjectName, aFeatureDimensions, -1);
-            else
+            std::list<std::map<std::string, std::string>>::iterator itList = aFeatureDimensionsList.begin();
+            for (; itList != aFeatureDimensionsList.end(); ++itList)
             {
-                aListOfMedias.push_back(aFeatureDimensions["medium"]);
-                anAlgo->buildVolume(anObjectName, aFeatureDimensions, ++aMediumIndex);
-            }
 
-            // Add volume to known ones with no translation
-            aListOfVolumes[anObjectName] = "";
+                std::map<std::string, std::string> aFeatureDimensions = *itList;
+                std::wstring anObjectName = (*aResIt)->data()->name();
+                // Filter on already created medias
+                std::list<std::string>::iterator anIter = std::find(aListOfMedias.begin(), aListOfMedias.end(), aFeatureDimensions["medium"]);
+                if (anIter != aListOfMedias.end())
+                    anAlgo->buildVolume(anObjectName, aFeatureDimensions, -1);
+                else
+                {
+                    aListOfMedias.push_back(aFeatureDimensions["medium"]);
+                    anAlgo->buildVolume(anObjectName, aFeatureDimensions, ++aMediumIndex);
+                }
+                aResIt++;
+            }
         }
         else if (aFeature->getKind() == "AddNode")
-        {
-            std::map<std::string, std::wstring> aFeatureDimensions;
-            aFeatureDimensions = ExchangePlugin_ExportRoot::computeAddNode(aFeature);
-            std::wstring anObjectName = aFeature->firstResult()->data()->name();
-
-            //Filter copied volumes
-            auto anIter = aListOfVolumes.find(aFeatureDimensions["tool"]);
-            if (anIter != aListOfVolumes.end())
-                anAlgo->buildAddNode(aFeatureDimensions, anIter->second, aCopyData);
-        }
-        else if (aFeature->getKind() == "Copy")
-        {
-            std::map<std::string, std::vector<std::array<std::string, 2>>> aFeatureDimensions;
-            aFeatureDimensions = ExchangePlugin_ExportRoot::computeCopy(aFeature);
-            aCopyData.insert(aFeatureDimensions.begin(), aFeatureDimensions.end());
-        }
-        else if (aFeature->getKind() == "Translation")
         {
             std::map<std::string, std::string> aFeatureDimensions;
-            aFeatureDimensions = ExchangePlugin_ExportRoot::computeTranslation(aFeature);
-            if (aFeatureDimensions.size())
-            {
-                std::map<std::string, std::string>::iterator it;
-                for (std::map<std::string, std::string>::iterator it = aFeatureDimensions.begin(); it != aFeatureDimensions.end(); it++)
-                {
-                    std::wstring aWStr(it->first.begin(), it->first.end());
-                    if (aListOfVolumes.find(aWStr) != aListOfVolumes.end())
-                        aListOfVolumes[aWStr] = it->second;
-                    else
-                    {
-                        for (auto jt = aCopyData.begin(); jt != aCopyData.end(); jt++)
-                            for (int k = 0; k < jt->second.size(); k++ )
-                                if (jt->second[k][0] == it->first)
-                                    jt->second[k][1] = it->second;
-                    }
-                }
-            } else {std::cout << "Ignoring translation" << std::endl;} //Filter translation not on volume or addNode
+            aFeatureDimensions = ExchangePlugin_ExportRoot::computeAddNode(aFeature);
+            anAlgo->buildAddNode(aFeatureDimensions);
         }
     }
 
index d02c5deaf2c2900413aa60177433be48e51f9cb2..32f309d71b53f62e64f7b4a96a2be67d539aa99a 100644 (file)
@@ -17,8 +17,6 @@
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#include <FeaturesPlugin_Copy.h>
-#include <FeaturesPlugin_Translation.h>
 
 #include <PrimitivesPlugin_Box.h>
 #include <PrimitivesPlugin_Cylinder.h>
 
 #include <GeomAlgoAPI_PointBuilder.h>
 
-#include <ModelAPI_AttributeDouble.h>
-#include <ModelAPI_AttributeInteger.h>
-#include <ModelAPI_AttributeSelectionList.h>
-
 #include <string>
-#include <iomanip>
-#include <sstream>
 #include "math.h"
 
                                                                                                                    namespace ExchangePlugin_ExportRoot
     }
 
     //===============================================================================================
-    std::map<std::string, std::string> computeVolume(FeaturePtr theFeature)
+    std::list<std::map<std::string, std::string>> computeVolume(FeaturePtr theFeature)
     {
         std::string aMedium;
+        std::list<std::map<std::string, std::string>> aVolList;
 
         //Get attributes
         aMedium = (theFeature->data()->string(OperaPlugin_Volume::MEDIUM_ID())->value());
-        AttributeSelectionPtr aSel = theFeature->data()->selectionList(OperaPlugin_Volume::OBJECTS_LIST_ID())->value(0);
-
-        //Get feature
-        ResultPtr aResult = aSel->context();
-        FeaturePtr aSelFeature = aResult->document()->feature(aResult);
-        std::string aKind = aSelFeature->getKind();
+        AttributeSelectionListPtr aSelList = theFeature->data()->selectionList(OperaPlugin_Volume::OBJECTS_LIST_ID());
+        std::cout << "size = " << aSelList->size() << std::endl;
 
-        //Data out
-        std::wstring aWShapeName = aResult ? aResult->data()->name() : aSelFeature->firstResult()->data()->name();
-        std::map<std::string, std::string> aFeatureDim;
-        aFeatureDim["medium"] = aMedium;
+        for (int anIndex = 0; anIndex < aSelList->size(); ++anIndex)
+        {
+            std::cout << "i = " << anIndex << std::endl;
+            // Get feature
+            ResultPtr aResult = aSelList->value(anIndex)->context();
+            FeaturePtr aSelFeature = aResult->document()->feature(aResult);
+            std::string aKind = aSelFeature->getKind();
+
+            // Data out
+            std::wstring aWShapeName = aResult ? aResult->data()->name() : aSelFeature->firstResult()->data()->name();
+            std::map<std::string, std::string> aFeatureDim;
+            aFeatureDim["medium"] = aMedium;
 
-        std::string aShapeName(aWShapeName.begin(), aWShapeName.end());
-        aFeatureDim["shape"] = aShapeName;
+            std::string aShapeName(aWShapeName.begin(), aWShapeName.end());
+            aFeatureDim["shape"] = aShapeName;
 
-        return aFeatureDim;
+            aVolList.push_back(aFeatureDim);
+        }
+        return aVolList;
     }
 
     //===============================================================================================
-    std::map<std::string, std::wstring> computeAddNode(FeaturePtr theFeature)
+    std::map<std::string, std::string> computeAddNode(FeaturePtr theFeature)
     {
         //Get attributes
         std::string aMedium;
         // Get attributes
         AttributeSelectionPtr aMainSel = theFeature->data()->selection(OperaPlugin_AddNode::MAIN_OBJECT_ID());
         AttributeSelectionPtr aToolSel = theFeature->data()->selection(OperaPlugin_AddNode::TOOL_OBJECT_ID());
+        double DX = (theFeature->data()->real(OperaPlugin_AddNode::DX_ID())->value());
+        double DY = (theFeature->data()->real(OperaPlugin_AddNode::DY_ID())->value());
+        double DZ = (theFeature->data()->real(OperaPlugin_AddNode::DZ_ID())->value());
 
         // Get main data
         ResultPtr aMainResult = aMainSel->context();
         ResultPtr aToolResult = aToolSel->context();
         FeaturePtr aToolSelFeature = aToolResult->document()->feature(aToolResult);
         std::wstring aWToolName = aToolResult ? aToolResult->data()->name() : aToolSelFeature->firstResult()->data()->name();
+        //Convert Wstring to string
+        std::string aMainName(aWMainName.begin(), aWMainName.end());
+        std::string aToolName(aWToolName.begin(), aWToolName.end());
 
         // Data out
-        std::map<std::string, std::wstring> aFeatureDim;
-        aFeatureDim["main"] = aWMainName;
-        aFeatureDim["tool"] = aWToolName;
+        std::map<std::string, std::string> aFeatureDim;
+        aFeatureDim["main"] = aMainName;
+        aFeatureDim["tool"] = aToolName;
+        aFeatureDim["dx"] = std::to_string(DX);
+        aFeatureDim["dy"] = std::to_string(DY);
+        aFeatureDim["dz"] = std::to_string(DZ);
 
         return aFeatureDim;
     }
 
-    //===============================================================================================
-    std::map<std::string, std::vector<std::array<std ::string, 2>>> computeCopy(FeaturePtr theFeature)
-    {
-        // Initialisation
-        std::map<std::string, std::vector<std::array<std :: string, 2>>> aFeatureDim;
-
-        // Get attributes
-        AttributeSelectionListPtr aBaseObjectList = theFeature->data()->selectionList(FeaturesPlugin_Copy::OBJECTS());
-        int aNumberOfCopies = theFeature->data()->integer(FeaturesPlugin_Copy::NUMBER())->value();
-
-        for (int anIndex = 0; anIndex < aBaseObjectList->size(); ++anIndex)
-        {
-            AttributeSelectionPtr aSelection = aBaseObjectList->value(anIndex);
-            ResultPtr aMainResult = aSelection->context();
-            FeaturePtr aSelectionFeature = aMainResult->document()->feature(aMainResult);
-            std::wstring aWSelName = aMainResult ? aMainResult->data()->name() : aSelectionFeature->firstResult()->data()->name();
-            std::string aSelName(aWSelName.begin(), aWSelName.end());
-            std::vector<std::array<std::string, 2>> aNewBaseCopies;
-            for (int i = 0; i < aNumberOfCopies; i++)
-            {
-                std::array <std::string, 2> aNewCopy = {aSelName + "_" + std::to_string(i+1), "0,0,0"}; //TODO : Get "copy result name"
-                aNewBaseCopies.push_back(aNewCopy);
-            }
-            aFeatureDim[aSelName] = aNewBaseCopies;
-        }
-        return aFeatureDim;
-    }
-
-    //===============================================================================================
-    std::map<std::string, std::string> computeTranslation(FeaturePtr theFeature)
-    {
-        AttributeStringPtr aMethodTypeAttr = theFeature->data()->string(FeaturesPlugin_Translation::CREATION_METHOD());
-        std::string aMethodType = aMethodTypeAttr->value();
-
-        if (aMethodType == FeaturesPlugin_Translation::CREATION_METHOD_BY_DIMENSIONS())
-        {
-            double DX, DY, DZ;
-            std::map<std::string, std::string> aFeatureDim;
-
-            DX = (theFeature->data()->real(FeaturesPlugin_Translation::DX_ID())->value());
-            DY = (theFeature->data()->real(FeaturesPlugin_Translation::DY_ID())->value());
-            DZ = (theFeature->data()->real(FeaturesPlugin_Translation::DZ_ID())->value());
-
-            AttributeSelectionListPtr aBaseObjectList = theFeature->data()->selectionList(FeaturesPlugin_Translation::OBJECTS_LIST_ID());
-            for (int anIndex = 0; anIndex < aBaseObjectList->size(); ++anIndex)
-            {
-                //Get new target object name
-                AttributeSelectionPtr aSelection = aBaseObjectList->value(anIndex);
-                ResultPtr aMainResult = aSelection->context();
-                FeaturePtr aSelectionFeature = aMainResult->document()->feature(aMainResult);
-                std::wstring aWSelName = aMainResult ? aMainResult->data()->name() : aSelectionFeature->firstResult()->data()->name();
-                std::string aSelName(aWSelName.begin(), aWSelName.end());
-                //Add it to translated objects
-                std::stringstream ss;
-                ss << std::fixed << std::setprecision(3) << DX << "," << DY << "," << DZ;
-                std::string aTrStr = ss.str();
-                aFeatureDim[aSelName] = aTrStr;
-            }
-            return aFeatureDim;
-        }
-        else
-        {
-            std::map<std::string, std::string> aFeatureDim;
-            return aFeatureDim;
-        }
-    }
-
 } // namespace ExchangePlugin_ExportRoot
index 705f91a3e9325be6ce118fe48d1beeff1690a5a3..77871eba41895a896a03ce2c231d107566aeb812 100644 (file)
@@ -28,10 +28,8 @@ namespace ExchangePlugin_ExportRoot
   /// \param[out] theDimensions dimensions of the box
   EXCHANGEPLUGIN_EXPORT std::map<std::string, double> computeBox(FeaturePtr theFeature);
   EXCHANGEPLUGIN_EXPORT std::map<std::string, double> computeCylinder(FeaturePtr theFeature);
-  EXCHANGEPLUGIN_EXPORT std::map<std::string, std::string> computeVolume(FeaturePtr theFeature);
-  EXCHANGEPLUGIN_EXPORT std::map<std::string, std::wstring> computeAddNode(FeaturePtr theFeature);
-  EXCHANGEPLUGIN_EXPORT std::map<std::string, std::vector<std::array<std ::string, 2>>> computeCopy(FeaturePtr theFeature);
-  EXCHANGEPLUGIN_EXPORT std::map<std::string, std::string> computeTranslation(FeaturePtr theFeature);
+  EXCHANGEPLUGIN_EXPORT std::list<std::map<std::string, std::string>> computeVolume(FeaturePtr theFeature);
+  EXCHANGEPLUGIN_EXPORT std::map<std::string, std::string> computeAddNode(FeaturePtr theFeature);
 }
 
 #endif /* EXCHANGEPLUGIN_EXPORTROOT_H_ */
index 451568a383dae46cae54ae476f437c01f7a41bbf..3590dfaa9e36ba7121a43000e29759abfac9d319 100644 (file)
@@ -26,6 +26,8 @@
 
 #include <map>
 #include <vector>
+#include <sstream>
+#include "math.h"
 
 //=================================================================================================
 static std::string doubleToString(const double &theValue)
@@ -147,42 +149,22 @@ void GeomAlgoAPI_ROOTExport::buildVolume(const std::wstring &theObjectName,
 }
 
 //=================================================================================================
-void GeomAlgoAPI_ROOTExport::buildAddNode(const std::map<std::string, std::wstring> theFeatureDim,
-                                          const std::string theVolumeTranslation,
-                                          const std::map<std::string, std::vector<std::array<std::string, 2>>> theCopyData)
+void GeomAlgoAPI_ROOTExport::buildAddNode(const std::map<std::string, std::string> theFeatureDim)
 {
     static int theAddNodeIndex = 0;
 
-    std::string aMainName(theFeatureDim["main"].begin(), theFeatureDim["main"].end());
-    std::string aToolName(theFeatureDim["tool"].begin(), theFeatureDim["tool"].end());
+    //Create string for translation
+    std::stringstream ss;
+    ss << std::fixed << std::setprecision(3) << theFeatureDim["dx"] << "," << theFeatureDim["dy"] << "," << theFeatureDim["dz"];
+    std::string aVolumeTranslation = ss.str();
 
+    //Write content
     myContent << "\t"
               << "//Exporting AddNode " << theAddNodeIndex << std::endl;
-
-    if (theVolumeTranslation.empty())
-    {
-        myContent << "\t"
-                  << aMainName << "->AddNode(" << aToolName << ", " << ++theAddNodeIndex << ");"
-                  << std::endl;
-    }
-    else
-    {
-        myContent << "\t"
-                  << aMainName << "->AddNode(" << aToolName << ", " << ++theAddNodeIndex << ", "
-                  << "new TGeoTranslation(" << theVolumeTranslation << "));"
-                  << std::endl;
-    }
-
-    for (auto const &[key, val] : theCopyData){
-        if (key == aToolName){
-            for (auto& el: val){
-                myContent << "\t"
-                          << aMainName << "->AddNode(" << aToolName << ", " << ++theAddNodeIndex << ", "
-                          << "new TGeoTranslation(" << el[1] <<"));"
-                          << std::endl;
-            }
-        }
-    }
+    myContent << "\t"
+                << theFeatureDim["main"] << "->AddNode(" << theFeatureDim["tool"] << ", " << ++theAddNodeIndex << ", "
+                << "new TGeoTranslation(" << aVolumeTranslation << "));"
+                << std::endl;
     myContent << std::endl;
 }
 
index 85b572093f7c38335094cef1c93e01d289c4ecd2..b1492e0ac7c6f0596aeaed1a78e7d4e84b118ec7 100644 (file)
@@ -63,9 +63,7 @@ public:
                                         const int theMediumIndex);
 
     /// Build AddNode
-    GEOMALGOAPI_EXPORT void buildAddNode(const std::map<std::string, std::wstring> theFeatureDim,
-                                         const std::string theVolumeTranslation,
-                                         const std::map<std::string, std::vector<std::array<std::string, 2>>> theCopyData);
+    GEOMALGOAPI_EXPORT void buildAddNode(const std::map<std::string, std::string> theFeatureDim);
     /// Build Medium
     GEOMALGOAPI_EXPORT void addMedium(const std::string theMediumName);
 
index 0fa0bce94e97f6700a614ddfe3adcc15de7970ee..6eda7dee6f3d8ac51f16e5e33c5efcb8fe3fe465 100644 (file)
@@ -48,11 +48,17 @@ public:
   OPERAAPI_EXPORT
   virtual ~OperaAPI_AddNode();
 
-  INTERFACE_2(OperaPlugin_AddNode::ID(),
+  INTERFACE_5(OperaPlugin_AddNode::ID(),
               mainObject, OperaPlugin_AddNode::MAIN_OBJECT_ID(),
               ModelAPI_AttributeSelection, /** Main Object */,
               toolObject, OperaPlugin_AddNode::TOOL_OBJECT_ID(),
-              ModelAPI_AttributeSelection, /** Tool Object*/)
+              ModelAPI_AttributeSelection, /** Tool Object*/,
+              dx, OperaPlugin_AddNode::DX_ID(),
+              ModelAPI_AttributeDouble, /** DX Value*/,
+              dy, OperaPlugin_AddNode::DY_ID(),
+              ModelAPI_AttributeDouble, /** DX Value*/,
+              dz, OperaPlugin_AddNode::DZ_ID(),
+              ModelAPI_AttributeDouble, /** DX Value*/)
 
   /// Set main object
   OPERAAPI_EXPORT
index a78b5a013fffb71b9be36bf201b00dd3ec1daa86..d1c2c285830cf77c7fe946701ec29c6c5fc82da2 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "OperaPlugin_AddNode.h"
 
-#include <ModelAPI_Feature.h>
+#include<cmath>
 
 //=================================================================================================
 OperaPlugin_AddNode::OperaPlugin_AddNode() // Nothing to do during instantiation
@@ -31,9 +31,11 @@ void OperaPlugin_AddNode::initAttributes()
 {
   data()->addAttribute(MAIN_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
   data()->addAttribute(TOOL_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(DX_ID(), ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(DY_ID(), ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(DZ_ID(), ModelAPI_AttributeDouble::typeId());
 }
 
-
 //=================================================================================================
 void OperaPlugin_AddNode::handleNaming(const GeomMakeShapePtr& theBoolAlgo,
                                        const GeomShapePtr theTool,
@@ -66,14 +68,65 @@ void OperaPlugin_AddNode::handleNaming(const GeomMakeShapePtr& theBoolAlgo,
   }
 }
 
+//=================================================================================================
+std::shared_ptr<GeomAPI_Pnt> OperaPlugin_AddNode::getBoundingBoxCenter(const GeomShapePtr &theShape)
+{
+  // Bounding point min/max coordinates
+  std::string anError;
+  double aXmin, aXmax, aYmin, aYmax, aZmin, aZmax;
+
+  // Bounding box points
+  if (!GetBoundingBox(theShape, aXmin, aXmax, aYmin, aYmax, aZmin, aZmax, anError))
+    return NULL;
+
+  //Retrun middle point from bounding box
+  return (GeomAlgoAPI_PointBuilder::vertex((aXmin + aXmax) / 2, (aYmin + aYmax) / 2, (aZmin + aZmax) / 2))->point();
+}
 
 //=================================================================================================
 void OperaPlugin_AddNode::performAlgo(const GeomShapePtr& theObject,
                                       GeomShapePtr theTool,
                                       const ListOfShape& theToolsList)
 {
-  //Intersecting tool case
-  if (theObject->intersect(theTool)){
+  //Get points
+  std::string anError;
+  std::shared_ptr<GeomAPI_Pnt> aStartPoint;
+  std::shared_ptr<GeomAPI_Pnt> anEndPoint;
+
+  //Get bounding box center for translation
+  aStartPoint = getBoundingBoxCenter(theTool);
+  anEndPoint = getBoundingBoxCenter(theObject);
+
+  if (!aStartPoint || !anEndPoint)
+    return setError("Error in bounding box calculation :" + anError);
+
+  //If not already in center, move it
+  float conf = 0.000001; // get Precision:Confusion
+  if (aStartPoint->distance(anEndPoint) > conf)
+  {
+    //Perform translation to tool's center of mass
+    std::shared_ptr<GeomAlgoAPI_Translation> aTranslationAlgoByPoint;
+    aTranslationAlgoByPoint.reset(new GeomAlgoAPI_Translation(theTool, aStartPoint, anEndPoint));
+    // Check for error
+    if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aTranslationAlgoByPoint, getKind(), anError))
+      return setError(anError);
+    theTool = aTranslationAlgoByPoint->shape();
+  }
+  //Perform translation from tool's  center of mass
+  double aDX = real(OperaPlugin_AddNode::DX_ID())->value();
+  double aDY = real(OperaPlugin_AddNode::DY_ID())->value();
+  double aDZ = real(OperaPlugin_AddNode::DZ_ID())->value();
+
+  std::shared_ptr<GeomAlgoAPI_Translation> aTranslationAlgoByDim;
+  aTranslationAlgoByDim.reset(new GeomAlgoAPI_Translation(theTool, aDX, aDY, aDZ));
+  // Check for error
+  if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aTranslationAlgoByDim, getKind(), anError))
+    return setError(anError);
+  theTool = aTranslationAlgoByDim->shape();
+
+  // Intersecting tool case
+  if (theObject->intersect(theTool))
+  {
     std::shared_ptr<GeomAlgoAPI_MakeShape> aCommonAlgo;
     aCommonAlgo.reset(new GeomAlgoAPI_Boolean(theObject,
                                               theTool,
@@ -81,13 +134,12 @@ void OperaPlugin_AddNode::performAlgo(const GeomShapePtr& theObject,
     theTool = aCommonAlgo->shape();
   }
 
-  //Perform algorithm
+  //Perform Add Node Algorithm
   std::shared_ptr<GeomAlgoAPI_MakeShape> aBoolAlgo;
   aBoolAlgo.reset(new GeomAlgoAPI_Boolean(theObject,
                                           theTool,
                                           GeomAlgoAPI_Tools::BOOL_CUT));
   //Check for error
-  std::string anError;
   if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aBoolAlgo, getKind(), anError))
     return setError(anError);
 
@@ -132,8 +184,6 @@ void OperaPlugin_AddNode::execute()
   }
 
   // Get Case
-  if (!aMainObjectShape->isIntersect(aToolShape))
-    return setError("Error: All tools must intersect the main object");
   if(aMainObjectShape == nullptr )
     return setError("Error: cannot perform an AddNode with no main object.");
   if(aToolShape == nullptr)
index f10b429fb227be8b9f50fe230ba2bb1b70599e3b..c58d86700f38f746be2af4f1b6026c09392f2ae2 100644 (file)
 #include "GeomAPI_ShapeIterator.h"
 
 #include <GeomAlgoAPI_Boolean.h>
+#include <GeomAlgoAPI_BoundingBox.h>
+#include <GeomAlgoAPI_Box.h>
 #include <GeomAlgoAPI_CompoundBuilder.h>
+#include <GeomAlgoAPI_PointBuilder.h>
 #include <GeomAlgoAPI_ShapeBuilder.h>
 #include "GeomAlgoAPI_Tools.h"
+#include <GeomAlgoAPI_Translation.h>
 
+#include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_Data.h>
@@ -67,19 +72,43 @@ class OperaPlugin_AddNode : public ModelAPI_Feature
       return MY_TOOL_OBJECT_ID;
     }
 
+    /// Attribute name of dimension in X.
+    inline static const std::string& DX_ID()
+    {
+      static const std::string MY_DX_ID("dx");
+      return MY_DX_ID;
+    }
+
+    /// Attribute name of dimension in X.
+    inline static const std::string &DY_ID()
+    {
+      static const std::string MY_DY_ID("dy");
+      return MY_DY_ID;
+    }
+
+    /// Attribute name of dimension in X.
+    inline static const std::string &DZ_ID()
+    {
+      static const std::string MY_DZ_ID("dz");
+      return MY_DZ_ID;
+    }
+
     /// Perform boolean alogrithm according to AddNode cases
     void performAlgo(const GeomShapePtr& theObject,
                      GeomShapePtr theTool,
                      const ListOfShape& theToolsList);
 
     /// Creates naming for AddNode results
-    void OperaPlugin_AddNode::handleNaming(const GeomMakeShapePtr& theBoolAlgo,
-                                           const GeomShapePtr theTool,
-                                           const ListOfShape& theToolsList);
+    void handleNaming(const GeomMakeShapePtr& theBoolAlgo,
+                      const GeomShapePtr theTool,
+                      const ListOfShape& theToolsList);
 
     /// Creates a new part document if needed
     OPERAPLUGIN_EXPORT virtual void execute();
 
+    /// Get bounding box center for tranlation
+    OPERAPLUGIN_EXPORT virtual std::shared_ptr<GeomAPI_Pnt> OperaPlugin_AddNode::getBoundingBoxCenter(const GeomShapePtr &theShape);
+
     /// Request for initialization of data model of the feature: adding all attributes
     OPERAPLUGIN_EXPORT virtual void initAttributes();
 
index d8b3ddb6e9ac5eefbe5739dffea56d737d4fb0ea..1a2fa49cb9c75f292271395f3ce0f953f1163e4a 100644 (file)
@@ -1,16 +1,37 @@
 <source>
   <shape_selector id="main_object"
-                  label="Main object"
-                  tooltip="Select a main object"
-                  shape_types="solids compounds"
-                  concealment="true">
-    <validator id="GeomValidators_ShapeType" parameters="solid compound"/>
+    label="Main object"
+    tooltip="Select a main object"
+    shape_types="solids compounds"
+    concealment="true">
+    <validator id="GeomValidators_ShapeType" parameters="solid compound" />
   </shape_selector>
   <shape_selector id="tool_object"
-                  label="Tool object"
-                  tooltip="Select a tool object"
-                  shape_types="solids compounds"
-                  concealment="true">
-    <validator id="GeomValidators_ShapeType" parameters="solid compound"/>
+    label="Tool object"
+    tooltip="Select a tool object"
+    shape_types="solids compounds"
+    concealment="false">
+    <validator id="GeomValidators_ShapeType" parameters="solid compound" />
   </shape_selector>
+  <doublevalue id="dx"
+    label="DX"
+    step="1.0"
+    default="0"
+    icon=""
+    tooltip="Translation in X">
+  </doublevalue>
+  <doublevalue id="dy"
+    label="DY"
+    step="1.0"
+    default="0"
+    icon=""
+    tooltip="Translation in Y">
+  </doublevalue>
+  <doublevalue id="dz"
+    label="DZ"
+    step="1.0"
+    default="0"
+    icon=""
+    tooltip="Translation in Z">
+  </doublevalue>
 </source>
index a0cbd22b747caf44c17006558e3472d21897bd47..25add9c2cfa41d389d9fa0aa2a30c9065edf2883 100644 (file)
@@ -7,7 +7,7 @@
                   label="Objects"
                   tooltip="Select solid objects"
                   shape_types="solids"
-                  concealment="true">
+                  concealment="false">
     <validator id="GeomValidators_ShapeType" parameters="solid"/>
   </multi_selector>
 </source>