Salome HOME
updated copyright message
[modules/shaper.git] / src / PrimitivesPlugin / PrimitivesPlugin_Box.cpp
index 35541e240fab56bef2599e907f7d29d1f48824f8..31c50a4a3a22abf1f1789e66522b1817fa7531b1 100644 (file)
@@ -1,8 +1,21 @@
-// Copyright (C) 2014-2016 CEA/DEN, EDF R&D
-
-// File:        PrimitivesPlugin_Box.cpp
-// Created:     10 Mar 2016
-// Author:      Clarisse Genrault (CEA)
+// Copyright (C) 2014-2023  CEA, EDF
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 
 #include <PrimitivesPlugin_Box.h>
 
@@ -15,6 +28,7 @@
 #include <GeomAlgoAPI_PointBuilder.h>
 
 #include <memory>
+#include <iostream>
 
 //=================================================================================================
 PrimitivesPlugin_Box::PrimitivesPlugin_Box() // Nothing to do during instantiation
@@ -26,14 +40,24 @@ void PrimitivesPlugin_Box::initAttributes()
 {
   data()->addAttribute(PrimitivesPlugin_Box::CREATION_METHOD(), ModelAPI_AttributeString::typeId());
 
+  // Data for the first mode
   data()->addAttribute(PrimitivesPlugin_Box::DX_ID(), ModelAPI_AttributeDouble::typeId());
   data()->addAttribute(PrimitivesPlugin_Box::DY_ID(), ModelAPI_AttributeDouble::typeId());
   data()->addAttribute(PrimitivesPlugin_Box::DZ_ID(), ModelAPI_AttributeDouble::typeId());
 
-  data()->addAttribute(PrimitivesPlugin_Box::POINT_FIRST_ID(), 
+  // Data for the second mode
+  data()->addAttribute(PrimitivesPlugin_Box::POINT_FIRST_ID(),
                        ModelAPI_AttributeSelection::typeId());
   data()->addAttribute(PrimitivesPlugin_Box::POINT_SECOND_ID(),
                        ModelAPI_AttributeSelection::typeId());
+
+  // Data for the third mode
+  data()->addAttribute(PrimitivesPlugin_Box::OX_ID(), ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(PrimitivesPlugin_Box::OY_ID(), ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(PrimitivesPlugin_Box::OZ_ID(), ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(PrimitivesPlugin_Box::HALF_DX_ID(), ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(PrimitivesPlugin_Box::HALF_DY_ID(), ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(PrimitivesPlugin_Box::HALF_DZ_ID(), ModelAPI_AttributeDouble::typeId());
 }
 
 //=================================================================================================
@@ -41,12 +65,15 @@ void PrimitivesPlugin_Box::execute()
 {
   AttributeStringPtr aMethodTypeAttr = string(PrimitivesPlugin_Box::CREATION_METHOD());
   std::string aMethodType = aMethodTypeAttr->value();
-  
-  if (aMethodType == CREATION_METHOD_BY_DIMENSIONS()) 
+
+  if (aMethodType == CREATION_METHOD_BY_DIMENSIONS())
     createBoxByDimensions();
-  
-  if (aMethodType == CREATION_METHOD_BY_TWO_POINTS()) 
+
+  if (aMethodType == CREATION_METHOD_BY_TWO_POINTS())
     createBoxByTwoPoints();
+
+  if (aMethodType == CREATION_METHOD_BY_ONE_POINT_AND_DIMS())
+    createBoxByOnePointAndDims();
 }
 
 //=================================================================================================
@@ -57,16 +84,15 @@ void PrimitivesPlugin_Box::createBoxByDimensions()
   double aDz = real(PrimitivesPlugin_Box::DZ_ID())->value();
 
   std::shared_ptr<GeomAlgoAPI_Box> aBoxAlgo(new GeomAlgoAPI_Box(aDx,aDy,aDz));
-  
-  // These checks should be made to the GUI for the feature but 
+
+  // These checks should be made to the GUI for the feature but
   // the corresponding validator does not exist yet.
   if (!aBoxAlgo->check()) {
-    // The error is not displayed in a popup window. It must be in the status bar.
-    setError(aBoxAlgo->getError(), false);
+    setError(aBoxAlgo->getError());
     return;
   }
-  
-  // Build the box 
+
+  // Build the box
   aBoxAlgo->build();
 
   // Check if the creation of the box
@@ -78,21 +104,21 @@ void PrimitivesPlugin_Box::createBoxByDimensions()
     setError(aBoxAlgo->getError());
     return;
   }
-  
+
   int aResultIndex = 0;
-  ResultBodyPtr aResultBox = document()->createBody(data(), aResultIndex); 
+  ResultBodyPtr aResultBox = document()->createBody(data(), aResultIndex);
   loadNamingDS(aBoxAlgo, aResultBox);
   setResult(aResultBox, aResultIndex);
 }
 
 //=================================================================================================
-void PrimitivesPlugin_Box::createBoxByTwoPoints() 
+void PrimitivesPlugin_Box::createBoxByTwoPoints()
 {
   AttributeSelectionPtr aRef1 = data()->selection(PrimitivesPlugin_Box::POINT_FIRST_ID());
   AttributeSelectionPtr aRef2 = data()->selection(PrimitivesPlugin_Box::POINT_SECOND_ID());
-  
-  std::shared_ptr<GeomAlgoAPI_BoxPoints> aBoxAlgo;
-  
+
+  std::shared_ptr<GeomAlgoAPI_Box> aBoxAlgo;
+
   if ((aRef1.get() != NULL) && (aRef2.get() != NULL)) {
     GeomShapePtr aShape1 = aRef1->value();
     if (!aShape1.get()) //If we can't get the points directly, try getting them from the context
@@ -103,36 +129,78 @@ void PrimitivesPlugin_Box::createBoxByTwoPoints()
     if (aShape1 && aShape2){
       std::shared_ptr<GeomAPI_Pnt> aFirstPoint = GeomAlgoAPI_PointBuilder::point(aShape1);
       std::shared_ptr<GeomAPI_Pnt> aSecondPoint = GeomAlgoAPI_PointBuilder::point(aShape2);
-      aBoxAlgo = std::shared_ptr<GeomAlgoAPI_BoxPoints>(
-                                  new GeomAlgoAPI_BoxPoints(aFirstPoint,aSecondPoint));
+      aBoxAlgo = std::shared_ptr<GeomAlgoAPI_Box>(new GeomAlgoAPI_Box(aFirstPoint,aSecondPoint));
     }
   }
-  
-  // These checks should be made to the GUI for the feature but 
+
+  // These checks should be made to the GUI for the feature but
   // the corresponding validator does not exist yet.
   if (!aBoxAlgo->check()) {
-    // The error is not displayed in a popup window. It must be in the message console.
-    setError(aBoxAlgo->getError(), false);
+    setError(aBoxAlgo->getError());
     return;
   }
-  
-  // Build the box 
+
+  // Build the box
   aBoxAlgo->build();
 
   // Check if the creation of the box
   if(!aBoxAlgo->isDone()) {
     // The error is not displayed in a popup window. It must be in the message console.
-    setError(aBoxAlgo->getError(), false);
+    setError(aBoxAlgo->getError());
     return;
   }
   if(!aBoxAlgo->checkValid("Box builder with two points")) {
     // The error is not displayed in a popup window. It must be in the message console.
-    setError(aBoxAlgo->getError(), false);
+    setError(aBoxAlgo->getError());
     return;
   }
-  
+
   int aResultIndex = 0;
-  ResultBodyPtr aResultBox = document()->createBody(data(), aResultIndex); 
+  ResultBodyPtr aResultBox = document()->createBody(data(), aResultIndex);
+  loadNamingDS(aBoxAlgo, aResultBox);
+  setResult(aResultBox, aResultIndex);
+}
+
+//=================================================================================================
+void PrimitivesPlugin_Box::createBoxByOnePointAndDims()
+{
+  // Getting dx, dy and dz
+  double aDx = real(PrimitivesPlugin_Box::HALF_DX_ID())->value();
+  double aDy = real(PrimitivesPlugin_Box::HALF_DY_ID())->value();
+  double aDz = real(PrimitivesPlugin_Box::HALF_DZ_ID())->value();
+
+  // Getting point coordinates
+  double x = real(PrimitivesPlugin_Box::OX_ID())->value();
+  double y = real(PrimitivesPlugin_Box::OY_ID())->value();
+  double z = real(PrimitivesPlugin_Box::OZ_ID())->value();
+
+  std::shared_ptr<GeomAlgoAPI_Box> aBoxAlgo;
+  aBoxAlgo = std::shared_ptr<GeomAlgoAPI_Box>(new GeomAlgoAPI_Box(x,y,z,aDx,aDy,aDz));
+
+  // These checks should be made to the GUI for the feature but
+  // the corresponding validator does not exist yet.
+  if (!aBoxAlgo->check()) {
+    setError(aBoxAlgo->getError());
+    return;
+  }
+
+  // Build the box
+  aBoxAlgo->build();
+
+  // Check if the creation of the box
+  if(!aBoxAlgo->isDone()) {
+    // The error is not displayed in a popup window. It must be in the message console.
+    setError(aBoxAlgo->getError());
+    return;
+  }
+  if(!aBoxAlgo->checkValid("Box builder with one point and dimensions")) {
+    // The error is not displayed in a popup window. It must be in the message console.
+    setError(aBoxAlgo->getError());
+    return;
+  }
+
+  int aResultIndex = 0;
+  ResultBodyPtr aResultBox = document()->createBody(data(), aResultIndex);
   loadNamingDS(aBoxAlgo, aResultBox);
   setResult(aResultBox, aResultIndex);
 }
@@ -143,18 +211,18 @@ void PrimitivesPlugin_Box::loadNamingDS(std::shared_ptr<GeomAlgoAPI_Box> theBoxA
 {
   // Load the result
   theResultBox->store(theBoxAlgo->shape());
-  
+
   // Prepare the naming
   theBoxAlgo->prepareNamingFaces();
-  
+
   // Insert to faces
-  int num = 1;
-  std::map< std::string, std::shared_ptr<GeomAPI_Shape> > listOfFaces = 
+  std::map< std::string, std::shared_ptr<GeomAPI_Shape> > listOfFaces =
     theBoxAlgo->getCreatedFaces();
-  for (std::map< std::string, std::shared_ptr<GeomAPI_Shape> >::iterator 
-       it=listOfFaces.begin(); it!=listOfFaces.end(); ++it) {
-    std::shared_ptr<GeomAPI_Shape> aFace = (*it).second;
-    theResultBox->generated(aFace, (*it).first, num++);
+  for (std::map< std::string, std::shared_ptr<GeomAPI_Shape> >::iterator it = listOfFaces.begin();
+       it != listOfFaces.end();
+       ++it)
+  {
+    theResultBox->generated((*it).second, (*it).first);
   }
 }