]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Added "Multitranslation" feature.
authorClarisse Genrault <clarisse.genrault@cea.fr>
Tue, 14 Feb 2017 09:47:30 +0000 (10:47 +0100)
committerClarisse Genrault <clarisse.genrault@cea.fr>
Tue, 14 Feb 2017 09:47:30 +0000 (10:47 +0100)
src/FeaturesAPI/CMakeLists.txt
src/FeaturesAPI/FeaturesAPI_MultiTranslation.cpp [new file with mode: 0644]
src/FeaturesAPI/FeaturesAPI_MultiTranslation.h [new file with mode: 0644]
src/FeaturesPlugin/CMakeLists.txt
src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp [new file with mode: 0644]
src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.h [new file with mode: 0644]
src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp
src/FeaturesPlugin/icons/multitranslation.png [new file with mode: 0644]
src/FeaturesPlugin/multitranslation_widget.xml [new file with mode: 0644]
src/FeaturesPlugin/plugin-Features.xml
src/PythonAPI/model/features/__init__.py

index af088777a46c35ddc485c40ebfa18b4d3bc4de81..b8ad3fe095d90c0d3cb639b4e08eaf8ef0e48c61 100644 (file)
@@ -9,6 +9,7 @@ SET(PROJECT_HEADERS
   FeaturesAPI_Extrusion.h
   FeaturesAPI_ExtrusionBoolean.h
   FeaturesAPI_Intersection.h
+  FeaturesAPI_MultiTranslation.h
   FeaturesAPI_Partition.h
   FeaturesAPI_Pipe.h
   FeaturesAPI_Placement.h
@@ -28,6 +29,7 @@ SET(PROJECT_SOURCES
   FeaturesAPI_Extrusion.cpp
   FeaturesAPI_ExtrusionBoolean.cpp
   FeaturesAPI_Intersection.cpp
+  FeaturesAPI_MultiTranslation.cpp
   FeaturesAPI_Partition.cpp
   FeaturesAPI_Pipe.cpp
   FeaturesAPI_Placement.cpp
diff --git a/src/FeaturesAPI/FeaturesAPI_MultiTranslation.cpp b/src/FeaturesAPI/FeaturesAPI_MultiTranslation.cpp
new file mode 100644 (file)
index 0000000..6754b0f
--- /dev/null
@@ -0,0 +1,178 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        FeaturesAPI_MultiTranslation.cpp
+// Created:     09 Feb 2017
+// Author:      Clarisse Genrault (CEA)
+
+#include <FeaturesAPI_MultiTranslation.h>
+
+#include <ModelHighAPI_Dumper.h>
+#include <ModelHighAPI_Tools.h>
+
+//==================================================================================================
+FeaturesAPI_MultiTranslation::FeaturesAPI_MultiTranslation(
+  const std::shared_ptr<ModelAPI_Feature>& theFeature)
+: ModelHighAPI_Interface(theFeature)
+{
+  initialize();
+}
+
+//==================================================================================================
+FeaturesAPI_MultiTranslation::FeaturesAPI_MultiTranslation(
+  const std::shared_ptr<ModelAPI_Feature>& theFeature,
+  const std::list<ModelHighAPI_Selection>& theMainObjects,
+  const ModelHighAPI_Selection& theAxisObject,
+  const ModelHighAPI_Double& theStep,
+  const ModelHighAPI_Integer& theNumber)
+: ModelHighAPI_Interface(theFeature)
+{
+  if(initialize()) {
+    fillAttribute(theMainObjects, mainObjects());
+    fillAttribute(theAxisObject, firstAxisObject());
+    fillAttribute(theStep, firstStep());
+    fillAttribute("",useSecondDir());
+    setFirstNumber(theNumber);
+  }
+}
+
+//==================================================================================================
+FeaturesAPI_MultiTranslation::FeaturesAPI_MultiTranslation(
+  const std::shared_ptr<ModelAPI_Feature>& theFeature,
+  const std::list<ModelHighAPI_Selection>& theMainObjects,
+  const ModelHighAPI_Selection& theFirstAxisObject,
+  const ModelHighAPI_Double& theFirstStep,
+  const ModelHighAPI_Integer& theFirstNumber,
+  const ModelHighAPI_Selection& theSecondAxisObject,
+  const ModelHighAPI_Double& theSecondStep,
+  const ModelHighAPI_Integer& theSecondNumber)
+: ModelHighAPI_Interface(theFeature)
+{
+  if(initialize()) {
+    fillAttribute(theMainObjects, mainObjects());
+    fillAttribute(theFirstAxisObject, firstAxisObject());
+    fillAttribute(theFirstStep, firstStep());
+    fillAttribute(theFirstNumber, firstNumber());
+    fillAttribute(theSecondAxisObject, secondAxisObject());
+    fillAttribute(theSecondStep, secondStep());
+    fillAttribute("true",useSecondDir());
+    setSecondNumber(theSecondNumber);
+  }
+}
+
+//==================================================================================================
+FeaturesAPI_MultiTranslation::~FeaturesAPI_MultiTranslation()
+{
+}
+
+//==================================================================================================
+void FeaturesAPI_MultiTranslation::setMainObjects(
+  const std::list<ModelHighAPI_Selection>& theMainObjects)
+{
+  fillAttribute(theMainObjects, mainObjects());
+
+  execute();
+}
+
+//==================================================================================================
+void FeaturesAPI_MultiTranslation::setFirstAxisAndDistance(
+  const ModelHighAPI_Selection& theAxisObject,
+  const ModelHighAPI_Double& theDistance)
+{
+  fillAttribute(theAxisObject, firstAxisObject());
+  fillAttribute(theDistance, firstStep());
+
+  execute();
+}
+
+//==================================================================================================
+void FeaturesAPI_MultiTranslation::setSecondAxisAndDistance(
+  const ModelHighAPI_Selection& theAxisObject,
+  const ModelHighAPI_Double& theDistance)
+{
+  fillAttribute(theAxisObject, secondAxisObject());
+  fillAttribute(theDistance, secondStep());
+
+  execute();
+}
+
+//==================================================================================================
+void FeaturesAPI_MultiTranslation::setFirstNumber(const ModelHighAPI_Integer& theFirstNumber)
+{
+  fillAttribute(theFirstNumber, firstNumber());
+
+  execute();
+}
+
+//==================================================================================================
+void FeaturesAPI_MultiTranslation::setSecondNumber(const ModelHighAPI_Integer& theSecondNumber)
+{
+  fillAttribute(theSecondNumber, secondNumber());
+
+  execute();
+}
+
+//==================================================================================================
+void FeaturesAPI_MultiTranslation::dump(ModelHighAPI_Dumper& theDumper) const
+{
+  FeaturePtr aBase = feature();
+  const std::string& aDocName = theDumper.name(aBase->document());
+
+  AttributeSelectionListPtr anAttrObjects =
+    aBase->selectionList(FeaturesPlugin_MultiTranslation::OBJECTS_LIST_ID());
+  theDumper << aBase << " = model.addMultiTranslation(" << aDocName << ", " << anAttrObjects;
+  
+  AttributeSelectionPtr anAttrFirstAxis =
+    aBase->selection(FeaturesPlugin_MultiTranslation::AXIS_FIRST_DIR_ID());
+  AttributeDoublePtr anAttrFirstStep =
+    aBase->real(FeaturesPlugin_MultiTranslation::STEP_FIRST_DIR_ID());
+  AttributeIntegerPtr anAttrFirstNumber =
+    aBase->integer(FeaturesPlugin_MultiTranslation::NB_COPIES_FIRST_DIR_ID());
+  theDumper << ", " << anAttrFirstAxis << ", " << anAttrFirstStep;
+  theDumper << ", " << anAttrFirstNumber;
+      
+  if (aBase->string(FeaturesPlugin_MultiTranslation::USE_SECOND_DIR_ID())->isInitialized()
+      && !aBase->string(FeaturesPlugin_MultiTranslation::USE_SECOND_DIR_ID())->value().empty()) {
+    AttributeSelectionPtr anAttrSecondAxis =
+      aBase->selection(FeaturesPlugin_MultiTranslation::AXIS_SECOND_DIR_ID());
+    AttributeDoublePtr anAttrSecondStep =
+      aBase->real(FeaturesPlugin_MultiTranslation::STEP_SECOND_DIR_ID());
+    AttributeIntegerPtr anAttrSecondNumber =
+      aBase->integer(FeaturesPlugin_MultiTranslation::NB_COPIES_SECOND_DIR_ID());
+    theDumper << ", " << anAttrSecondAxis << ", " << anAttrSecondStep;
+    theDumper << ", " << anAttrSecondStep;
+  }
+
+  theDumper << ")" << std::endl;
+}
+
+//==================================================================================================
+MultiTranslationPtr addMultiTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
+                                        const std::list<ModelHighAPI_Selection>& theMainObjects,
+                                        const ModelHighAPI_Selection& theAxisObject,
+                                        const ModelHighAPI_Double& theStep,
+                                        const ModelHighAPI_Integer& theNumber)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature =
+    thePart->addFeature(FeaturesAPI_MultiTranslation::ID());
+  return MultiTranslationPtr(new FeaturesAPI_MultiTranslation(aFeature, theMainObjects,
+                                                              theAxisObject, theStep, theNumber));
+}
+
+//==================================================================================================
+MultiTranslationPtr addMultiTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
+                                        const std::list<ModelHighAPI_Selection>& theMainObjects,
+                                        const ModelHighAPI_Selection& theFirstAxisObject,
+                                        const ModelHighAPI_Double& theFirstStep,
+                                        const ModelHighAPI_Integer& theFirstNumber,
+                                        const ModelHighAPI_Selection& theSecondAxisObject,
+                                        const ModelHighAPI_Double& theSecondStep,
+                                        const ModelHighAPI_Integer& theSecondNumber)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature =
+    thePart->addFeature(FeaturesAPI_MultiTranslation::ID());
+  return MultiTranslationPtr(new FeaturesAPI_MultiTranslation(aFeature, theMainObjects,
+                                                              theFirstAxisObject, theFirstStep,
+                                                              theFirstNumber,
+                                                              theSecondAxisObject, theSecondStep,
+                                                              theSecondNumber));
+}
diff --git a/src/FeaturesAPI/FeaturesAPI_MultiTranslation.h b/src/FeaturesAPI/FeaturesAPI_MultiTranslation.h
new file mode 100644 (file)
index 0000000..a06c71f
--- /dev/null
@@ -0,0 +1,125 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        FeaturesAPI_MultiTranslation.h
+// Created:     09 Feb 2017
+// Author:      Clarisse Genrault (CEA)
+
+#ifndef FEATURESAPI_MULTITRANSLATION_H_
+#define FEATURESAPI_MULTITRANSLATION_H_
+
+#include "FeaturesAPI.h"
+
+#include <FeaturesPlugin_MultiTranslation.h>
+
+#include <ModelHighAPI_Interface.h>
+#include <ModelHighAPI_Macro.h>
+
+class ModelHighAPI_Double;
+class ModelHighAPI_Dumper;
+class ModelHighAPI_Integer;
+class ModelHighAPI_Selection;
+
+/// \class FeaturesAPI_MultiTranslation
+/// \ingroup CPPHighAPI
+/// \brief Interface for Translation feature.
+class FeaturesAPI_MultiTranslation: public ModelHighAPI_Interface
+{
+public:
+  /// Constructor without values.
+  FEATURESAPI_EXPORT
+  explicit FeaturesAPI_MultiTranslation(const std::shared_ptr<ModelAPI_Feature>& theFeature);
+
+  /// Constructor with values.
+  FEATURESAPI_EXPORT
+  explicit FeaturesAPI_MultiTranslation(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                        const std::list<ModelHighAPI_Selection>& theMainObjects,
+                                        const ModelHighAPI_Selection& theAxisObject,
+                                        const ModelHighAPI_Double& theStep,
+                                        const ModelHighAPI_Integer& theNumber);
+
+  /// Constructor with values.
+  FEATURESAPI_EXPORT
+  explicit FeaturesAPI_MultiTranslation(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                        const std::list<ModelHighAPI_Selection>& theMainObjects,
+                                        const ModelHighAPI_Selection& theFirstAxisObject,
+                                        const ModelHighAPI_Double& theFirstStep,
+                                        const ModelHighAPI_Integer& theFirstNumber,
+                                        const ModelHighAPI_Selection& theSecondAxisObject,
+                                        const ModelHighAPI_Double& theSecondStep,
+                                        const ModelHighAPI_Integer& theSecondNumber);
+
+  /// Destructor.
+  FEATURESAPI_EXPORT
+  virtual ~FeaturesAPI_MultiTranslation();
+
+  INTERFACE_8(FeaturesPlugin_MultiTranslation::ID(),
+              mainObjects, FeaturesPlugin_MultiTranslation::OBJECTS_LIST_ID(),
+              ModelAPI_AttributeSelectionList, /** Main objects */,
+              firstAxisObject, FeaturesPlugin_MultiTranslation::AXIS_FIRST_DIR_ID(),
+              ModelAPI_AttributeSelection, /** First axis object */,
+              firstStep, FeaturesPlugin_MultiTranslation::STEP_FIRST_DIR_ID(),
+              ModelAPI_AttributeDouble, /** First step */,
+              firstNumber, FeaturesPlugin_MultiTranslation::NB_COPIES_FIRST_DIR_ID(),
+              ModelAPI_AttributeInteger, /** First number of copies */,
+              useSecondDir, FeaturesPlugin_MultiTranslation::USE_SECOND_DIR_ID(),
+              ModelAPI_AttributeString, /** Use the second dir */,
+              secondAxisObject, FeaturesPlugin_MultiTranslation::AXIS_SECOND_DIR_ID(),
+              ModelAPI_AttributeSelection, /** Second axis object */,
+              secondStep, FeaturesPlugin_MultiTranslation::STEP_SECOND_DIR_ID(),
+              ModelAPI_AttributeDouble, /** Second step */,
+              secondNumber, FeaturesPlugin_MultiTranslation::NB_COPIES_SECOND_DIR_ID(),
+              ModelAPI_AttributeInteger, /** Second number of copies */
+             )
+
+  /// Set main objects.
+  FEATURESAPI_EXPORT
+  void setMainObjects(const std::list<ModelHighAPI_Selection>& theMainObjects);
+
+  /// Modify CreationMethod, axis_first_dir, step_first_dir attributes of the feature.
+  FEATURESAPI_EXPORT
+  void setFirstAxisAndDistance(const ModelHighAPI_Selection& theAxisObject,
+                               const ModelHighAPI_Double& theDistance);
+
+  /// Modify CreationMethod, axis_second_dir, step_second_dir attributes of the feature.
+  FEATURESAPI_EXPORT
+  void setSecondAxisAndDistance(const ModelHighAPI_Selection& theAxisObject,
+                                const ModelHighAPI_Double& theDistance);
+  
+  /// Modify CreationMethod, nb_first_dir attribute of the feature.
+  FEATURESAPI_EXPORT
+  void setFirstNumber(const ModelHighAPI_Integer& theFirstNumber);
+
+  /// Modify CreationMethod, nb_second_dir attribute of the feature.
+  FEATURESAPI_EXPORT
+  void setSecondNumber(const ModelHighAPI_Integer& theSecondNumber);
+
+  /// Dump wrapped feature
+  FEATURESAPI_EXPORT
+  virtual void dump(ModelHighAPI_Dumper& theDumper) const;
+};
+
+/// Pointer on Translation object.
+typedef std::shared_ptr<FeaturesAPI_MultiTranslation> MultiTranslationPtr;
+
+/// \ingroup CPPHighAPI
+/// \brief Create MultiTranslation feature.
+FEATURESAPI_EXPORT
+MultiTranslationPtr addMultiTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
+                                        const std::list<ModelHighAPI_Selection>& theMainObjects,
+                                        const ModelHighAPI_Selection& theAxisObject,
+                                        const ModelHighAPI_Double& theStep,
+                                        const ModelHighAPI_Integer& theNumber);
+
+/// \ingroup CPPHighAPI
+/// \brief Create MultiTranslation feature.
+FEATURESAPI_EXPORT
+MultiTranslationPtr addMultiTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
+                                        const std::list<ModelHighAPI_Selection>& theMainObjects,
+                                        const ModelHighAPI_Selection& theFirstAxisObject,
+                                        const ModelHighAPI_Double& theFirstStep,
+                                        const ModelHighAPI_Integer& theFirstNumber,
+                                        const ModelHighAPI_Selection& theSecondAxisObject,
+                                        const ModelHighAPI_Double& theSecondStep,
+                                        const ModelHighAPI_Integer& theSecondNumber);
+
+#endif // FEATURESAPI_MULTITRANSLATION_H_
index cf821fd9e051dc28768f43fdee83e6298cfbacc9..b36b59ff0a8fd933dfc4210d0baa32b977b76f73 100644 (file)
@@ -31,6 +31,7 @@ SET(PROJECT_HEADERS
     FeaturesPlugin_Tools.h
     FeaturesPlugin_Symmetry.h
     FeaturesPlugin_Scale.h
+    FeaturesPlugin_MultiTranslation.h
 )
 
 SET(PROJECT_SOURCES
@@ -60,6 +61,7 @@ SET(PROJECT_SOURCES
     FeaturesPlugin_Tools.cpp
     FeaturesPlugin_Symmetry.cpp
     FeaturesPlugin_Scale.cpp
+    FeaturesPlugin_MultiTranslation.cpp
 )
 
 SET(XML_RESOURCES
@@ -82,6 +84,7 @@ SET(XML_RESOURCES
   union_widget.xml
   symmetry_widget.xml
   scale_widget.xml
+  multitranslation_widget.xml
 )
 
 SET(TEXT_RESOURCES
diff --git a/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp b/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.cpp
new file mode 100644 (file)
index 0000000..d92efba
--- /dev/null
@@ -0,0 +1,328 @@
+// Copyright (C) 2014-201x CEA/DEN, EDF R&D
+
+// File:        FeaturesPlugin_MultiTranslation.cpp
+// Created:     30 Jan 2017
+// Author:      Clarisse Genrault (CEA)
+
+#include <FeaturesPlugin_MultiTranslation.h>
+
+#include <GeomAlgoAPI_CompoundBuilder.h>
+
+#include <GeomAPI_Ax1.h>
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Lin.h>
+
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_ResultBody.h>
+
+#include <math.h>
+
+//=================================================================================================
+FeaturesPlugin_MultiTranslation::FeaturesPlugin_MultiTranslation()
+{
+}
+
+//=================================================================================================
+void FeaturesPlugin_MultiTranslation::initAttributes()
+{
+  AttributeSelectionListPtr aSelection =
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->addAttribute(
+    FeaturesPlugin_MultiTranslation::OBJECTS_LIST_ID(),
+    ModelAPI_AttributeSelectionList::typeId()));
+
+  data()->addAttribute(FeaturesPlugin_MultiTranslation::AXIS_FIRST_DIR_ID(),
+                       ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(FeaturesPlugin_MultiTranslation::STEP_FIRST_DIR_ID(),
+                       ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(FeaturesPlugin_MultiTranslation::NB_COPIES_FIRST_DIR_ID(),
+                       ModelAPI_AttributeInteger::typeId());
+  
+  data()->addAttribute(FeaturesPlugin_MultiTranslation::USE_SECOND_DIR_ID(),
+                       ModelAPI_AttributeString::typeId());
+  data()->addAttribute(FeaturesPlugin_MultiTranslation::AXIS_SECOND_DIR_ID(),
+                       ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(FeaturesPlugin_MultiTranslation::STEP_SECOND_DIR_ID(),
+                       ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(FeaturesPlugin_MultiTranslation::NB_COPIES_SECOND_DIR_ID(),
+                       ModelAPI_AttributeInteger::typeId());
+}
+
+//=================================================================================================
+void FeaturesPlugin_MultiTranslation::execute()
+{
+  std::string useSecondDir = string(FeaturesPlugin_MultiTranslation::USE_SECOND_DIR_ID())->value();
+  if(!useSecondDir.empty()) {
+    performTwoDirection();
+  } else {
+    performOneDirection();
+  }
+}
+
+//=================================================================================================
+void FeaturesPlugin_MultiTranslation::performOneDirection()
+{
+  // Getting objects.
+  ListOfShape anObjects;
+  std::list<ResultPtr> aContextes;
+  AttributeSelectionListPtr anObjectsSelList =
+    selectionList(FeaturesPlugin_MultiTranslation::OBJECTS_LIST_ID());
+  if (anObjectsSelList->size() == 0) {
+    return;
+  }
+  for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
+    std::shared_ptr<ModelAPI_AttributeSelection> anObjectAttr =
+      anObjectsSelList->value(anObjectsIndex);
+    std::shared_ptr<GeomAPI_Shape> anObject = anObjectAttr->value();
+    if(!anObject.get()) { // may be for not-activated parts
+      eraseResults();
+      return;
+    }
+    anObjects.push_back(anObject);
+    aContextes.push_back(anObjectAttr->context());
+  }
+
+  //Getting axis.
+  std::shared_ptr<GeomAPI_Ax1> anAxis;
+  std::shared_ptr<GeomAPI_Edge> anEdge;
+  std::shared_ptr<ModelAPI_AttributeSelection> anObjRef =
+    selection(FeaturesPlugin_MultiTranslation::AXIS_FIRST_DIR_ID());
+  if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) {
+    anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->value()));
+  } else if (anObjRef && !anObjRef->value() && anObjRef->context() &&
+             anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) {
+    anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->context()->shape()));
+  }
+  if(anEdge) {
+    anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(),
+                                                          anEdge->line()->direction()));
+  }
+
+  // Getting step.
+  double aStep = real(FeaturesPlugin_MultiTranslation::STEP_FIRST_DIR_ID())->value();
+  
+  // Getting number of copies.
+  int nbCopies = 
+    integer(FeaturesPlugin_MultiTranslation::NB_COPIES_FIRST_DIR_ID())->value();
+  // Moving each object.
+  
+  int aResultIndex = 0;
+  std::list<ResultPtr>::iterator aContext = aContextes.begin();
+  for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end();
+        anObjectsIt++, aContext++) {
+    std::shared_ptr<GeomAPI_Shape> aBaseShape = *anObjectsIt;
+    
+    ListOfShape aListOfShape;
+    std::list<std::shared_ptr<GeomAlgoAPI_Translation> > aListOfTranslationAlgo;
+  
+    for (int i=0; i<nbCopies; i++) {
+      std::shared_ptr<GeomAlgoAPI_Translation> aTranslationAlgo(
+        new GeomAlgoAPI_Translation(aBaseShape, anAxis, i*aStep));
+      
+      if (!aTranslationAlgo->check()) {
+        setError(aTranslationAlgo->getError());
+        break;
+      }
+      
+      aTranslationAlgo->build();
+      
+      // Checking that the algorithm worked properly.
+      if (!aTranslationAlgo->isDone()) {
+        static const std::string aFeatureError = "Error : Multitranslation algorithm failed.";
+        setError(aFeatureError);
+        break;
+      }
+      if (aTranslationAlgo->shape()->isNull()) {
+        static const std::string aShapeError = "Error : Resulting shape is null.";
+        setError(aShapeError);
+        break;
+      }
+      if (!aTranslationAlgo->isValid()) {
+        static const std::string aFeatureError = "Error : Resulting shape in not valid.";
+        setError(aFeatureError);
+        break;
+      }
+      aListOfShape.push_back(aTranslationAlgo->shape());
+      aListOfTranslationAlgo.push_back(aTranslationAlgo);
+    }
+    std::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aListOfShape);
+    ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
+    aResultBody->storeModified(aBaseShape, aCompound);
+    loadNamingDS(aListOfTranslationAlgo, aResultBody, aBaseShape);
+    
+    setResult(aResultBody, aResultIndex);
+    aResultIndex++;
+  }
+
+  // Remove the rest results if there were produced in the previous pass.
+  removeResults(aResultIndex);
+}
+
+//=================================================================================================
+void FeaturesPlugin_MultiTranslation::performTwoDirection()
+{ 
+  // Getting objects.
+  ListOfShape anObjects;
+  std::list<ResultPtr> aContextes;
+  AttributeSelectionListPtr anObjectsSelList =
+    selectionList(FeaturesPlugin_MultiTranslation::OBJECTS_LIST_ID());
+  if (anObjectsSelList->size() == 0) {
+    return;
+  }
+  for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
+    std::shared_ptr<ModelAPI_AttributeSelection> anObjectAttr =
+      anObjectsSelList->value(anObjectsIndex);
+    std::shared_ptr<GeomAPI_Shape> anObject = anObjectAttr->value();
+    if(!anObject.get()) { // may be for not-activated parts
+      eraseResults();
+      return;
+    }
+    anObjects.push_back(anObject);
+    aContextes.push_back(anObjectAttr->context());
+  }
+
+  //Getting axis.
+  std::shared_ptr<GeomAPI_Ax1> aFirstAxis;
+  std::shared_ptr<GeomAPI_Edge> anEdge;
+  std::shared_ptr<ModelAPI_AttributeSelection> anObjRef =
+    selection(FeaturesPlugin_MultiTranslation::AXIS_FIRST_DIR_ID());
+  if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) {
+    anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->value()));
+  } else if (anObjRef && !anObjRef->value() && anObjRef->context() &&
+             anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) {
+    anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->context()->shape()));
+  }
+  if(anEdge) {
+    aFirstAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(),
+                                                              anEdge->line()->direction()));
+  }
+  std::shared_ptr<GeomAPI_Ax1> aSecondAxis;
+  anObjRef = selection(FeaturesPlugin_MultiTranslation::AXIS_SECOND_DIR_ID());
+  if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) {
+    anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->value()));
+  } else if (anObjRef && !anObjRef->value() && anObjRef->context() &&
+             anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) {
+    anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->context()->shape()));
+  }
+  if(anEdge) {
+    aSecondAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(),
+                                                               anEdge->line()->direction()));
+  }
+
+  // Getting step.
+  double aFirstStep = real(FeaturesPlugin_MultiTranslation::STEP_FIRST_DIR_ID())->value();
+  double aSecondStep = real(FeaturesPlugin_MultiTranslation::STEP_SECOND_DIR_ID())->value();
+  
+  // Getting number of copies.
+  int aFirstNbCopies = 
+    integer(FeaturesPlugin_MultiTranslation::NB_COPIES_FIRST_DIR_ID())->value();
+  int aSecondNbCopies = 
+    integer(FeaturesPlugin_MultiTranslation::NB_COPIES_SECOND_DIR_ID())->value();
+    
+  // Coord aFirstAxis
+  double x1 = aFirstAxis->dir()->x();
+  double y1 = aFirstAxis->dir()->y();
+  double z1 = aFirstAxis->dir()->z();
+  double norm1 = sqrt(x1*x1 + y1*y1 + z1*z1);
+  
+  // Coord aSecondAxis
+  double x2 = aSecondAxis->dir()->x();
+  double y2 = aSecondAxis->dir()->y();
+  double z2 = aSecondAxis->dir()->z();
+  double norm2 = sqrt(x2*x2 + y2*y2 + z2*z2);
+  // Moving each object.
+  int aResultIndex = 0;
+  std::list<ResultPtr>::iterator aContext = aContextes.begin();
+  for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end();
+        anObjectsIt++, aContext++) {
+    std::shared_ptr<GeomAPI_Shape> aBaseShape = *anObjectsIt;
+    
+    ListOfShape aListOfShape;
+    std::list<std::shared_ptr<GeomAlgoAPI_Translation> > aListOfTranslationAlgo;
+  
+    for (int j=0; j<aSecondNbCopies; j++) {
+      for (int i=0; i<aFirstNbCopies; i++) {
+        double dx = i*aFirstStep*x1/norm1+j*aSecondStep*x2/norm2;
+        double dy = i*aFirstStep*y1/norm1+j*aSecondStep*y2/norm2;
+        double dz = i*aFirstStep*z1/norm1+j*aSecondStep*z2/norm2;
+        std::shared_ptr<GeomAlgoAPI_Translation> aTranslationAlgo(
+          new GeomAlgoAPI_Translation(aBaseShape, dx, dy, dz));
+      
+        if (!aTranslationAlgo->check()) {
+          setError(aTranslationAlgo->getError());
+          break;
+        }
+      
+        aTranslationAlgo->build();
+      
+        // Checking that the algorithm worked properly.
+        if (!aTranslationAlgo->isDone()) {
+          static const std::string aFeatureError = "Error : Multitranslation algorithm failed.";
+          setError(aFeatureError);
+          break;
+        }
+        if (aTranslationAlgo->shape()->isNull()) {
+          static const std::string aShapeError = "Error : Resulting shape is null.";
+          setError(aShapeError);
+          break;
+        }
+        if (!aTranslationAlgo->isValid()) {
+          static const std::string aFeatureError = "Error : Resulting shape in not valid.";
+          setError(aFeatureError);
+          break;
+        }
+        aListOfShape.push_back(aTranslationAlgo->shape());
+        aListOfTranslationAlgo.push_back(aTranslationAlgo);
+      }
+    }
+    std::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aListOfShape);
+    ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
+    aResultBody->storeModified(aBaseShape, aCompound);
+    loadNamingDS(aListOfTranslationAlgo, aResultBody, aBaseShape);
+    setResult(aResultBody, aResultIndex);
+    aResultIndex++;
+  }
+
+  // Remove the rest results if there were produced in the previous pass.
+  removeResults(aResultIndex);
+}
+
+//=================================================================================================
+void FeaturesPlugin_MultiTranslation::loadNamingDS(
+    std::list<std::shared_ptr<GeomAlgoAPI_Translation> > theListOfTranslationAlgo,
+    std::shared_ptr<ModelAPI_ResultBody> theResultBody,
+    std::shared_ptr<GeomAPI_Shape> theBaseShape)
+{
+  int aTag = 1;
+  int anIndex = 1;
+  std::string aTranslatedName;
+  
+  for (std::list<std::shared_ptr<GeomAlgoAPI_Translation> >::const_iterator anIt =
+    theListOfTranslationAlgo.begin(); anIt != theListOfTranslationAlgo.cend(); ++anIt) {
+    std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = (*anIt)->mapOfSubShapes();
+
+    // naming of faces
+    aTranslatedName = "Translated_Face_" + std::to_string((long long) anIndex);
+    theResultBody->loadAndOrientModifiedShapes((*anIt).get(), theBaseShape, GeomAPI_Shape::FACE,
+                                               aTag++, aTranslatedName, *aSubShapes.get(),
+                                               false, true);
+
+    // naming of edges
+    aTranslatedName = "Translated_Edge_" + std::to_string((long long) anIndex);
+    theResultBody->loadAndOrientModifiedShapes((*anIt).get(), theBaseShape, GeomAPI_Shape::EDGE,
+                                               aTag++, aTranslatedName, *aSubShapes.get(),
+                                               false, true);
+
+    // naming of vertex
+    aTranslatedName = "Translated_Vertex_" + std::to_string((long long) anIndex);
+    theResultBody->loadAndOrientModifiedShapes((*anIt).get(), theBaseShape, GeomAPI_Shape::VERTEX,
+                                               aTag++, aTranslatedName, *aSubShapes.get(),
+                                               false, true);
+    
+    ++anIndex;
+  }
+}
\ No newline at end of file
diff --git a/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.h b/src/FeaturesPlugin/FeaturesPlugin_MultiTranslation.h
new file mode 100644 (file)
index 0000000..8766442
--- /dev/null
@@ -0,0 +1,115 @@
+// Copyright (C) 2014-201x CEA/DEN, EDF R&D
+
+// File:        FeaturesPlugin_MultiTranslation.h
+// Created:     30 Jan 2017
+// Author:      Clarisse Genrault (CEA)
+
+#ifndef FEATURESPLUGIN_MULTITRANSLATION_H_
+#define FEATURESPLUGIN_MULTITRANSLATION_H_
+
+#include <FeaturesPlugin.h>
+
+#include <GeomAlgoAPI_Translation.h>
+
+#include <ModelAPI_Feature.h>
+
+/** \class FeaturesPlugin_MultiTranslation
+ *  \ingroup Plugins
+ *  \brief Feature for movement objects along one or two axes an arbitary number of times,
+ *         making a copy every time.
+ */
+class FeaturesPlugin_MultiTranslation : public ModelAPI_Feature
+{
+  public:
+  /// Translation kind.
+  inline static const std::string& ID()
+  {
+    static const std::string MY_MULTITRANSLATION_ID("MultiTranslation");
+    return MY_MULTITRANSLATION_ID;
+  }
+
+  /// Attribute name of referenced objects.
+  inline static const std::string& OBJECTS_LIST_ID()
+  {
+    static const std::string MY_OBJECTS_LIST_ID("main_objects");
+    return MY_OBJECTS_LIST_ID;
+  }
+
+  /// Attribute name of a first direction.
+  inline static const std::string& AXIS_FIRST_DIR_ID()
+  {
+    static const std::string MY_AXIS_FIRST_DIR_ID("axis_first_dir");
+    return MY_AXIS_FIRST_DIR_ID;
+  }
+
+  /// Attribute name of step for the first direction.
+  inline static const std::string& STEP_FIRST_DIR_ID()
+  {
+    static const std::string MY_STEP_FIRST_DIR_ID("step_first_dir");
+    return MY_STEP_FIRST_DIR_ID;
+  }
+
+  /// Attribute name of number of copies for the first direction.
+  inline static const std::string& NB_COPIES_FIRST_DIR_ID()
+  {
+    static const std::string MY_NB_COPIES_FIRST_DIR_ID("nb_first_dir");
+    return MY_NB_COPIES_FIRST_DIR_ID;
+  }
+
+  /// Attribute name for use second dir.
+  inline static const std::string& USE_SECOND_DIR_ID()
+  {
+    static const std::string MY_USE_SECOND_DIR_ID("use_second_dir");
+    return MY_USE_SECOND_DIR_ID;
+  }
+
+  /// Attribute name of a second direction.
+  inline static const std::string& AXIS_SECOND_DIR_ID()
+  {
+    static const std::string MY_AXIS_SECOND_DIR_ID("axis_second_dir");
+    return MY_AXIS_SECOND_DIR_ID;
+  }
+
+  /// Attribute name of step for the second direction.
+  inline static const std::string& STEP_SECOND_DIR_ID()
+  {
+    static const std::string MY_STEP_SECOND_DIR_ID("step_second_dir");
+    return MY_STEP_SECOND_DIR_ID;
+  }
+
+  /// Attribute name of number of copies for the second direction.
+  inline static const std::string& NB_COPIES_SECOND_DIR_ID()
+  {
+    static const std::string MY_NB_COPIES_SECOND_DIR_ID("nb_second_dir");
+    return MY_NB_COPIES_SECOND_DIR_ID;
+  }
+
+  /// \return the kind of a feature.
+  FEATURESPLUGIN_EXPORT virtual const std::string& getKind()
+  {
+    static std::string MY_KIND = FeaturesPlugin_MultiTranslation::ID();
+    return MY_KIND;
+  }
+
+  /// Creates a new part document if needed.
+  FEATURESPLUGIN_EXPORT virtual void execute();
+
+  /// Request for initialization of data model of the feature: adding all attributes.
+  FEATURESPLUGIN_EXPORT virtual void initAttributes();
+
+  /// Use plugin manager for features creation.
+  FeaturesPlugin_MultiTranslation();
+
+private:
+  /// Perform the multi translation in one direction.
+  void performOneDirection();
+
+  /// Perform the multi translation in two directions.
+  void performTwoDirection();
+
+  void loadNamingDS(std::list<std::shared_ptr<GeomAlgoAPI_Translation> > theListOfTranslationAlgo,
+                    std::shared_ptr<ModelAPI_ResultBody> theResultBody,
+                    std::shared_ptr<GeomAPI_Shape> theBaseShape);
+};
+
+#endif // FEATURESPLUGIN_MULTITRANSLATION_H_
\ No newline at end of file
index 4f1344b1d948c312cb220d3a4e670cb2a6e0f0a2..1509e6c776ec6d654f3293241fa90e03292050f8 100644 (file)
@@ -7,7 +7,7 @@
 #include <FeaturesPlugin_ExtrusionCut.h>
 #include <FeaturesPlugin_ExtrusionFuse.h>
 #include <FeaturesPlugin_Intersection.h>
-#include <FeaturesPlugin_Translation.h>
+#include <FeaturesPlugin_MultiTranslation.h>
 #include <FeaturesPlugin_Partition.h>
 #include <FeaturesPlugin_Pipe.h>
 #include <FeaturesPlugin_Placement.h>
@@ -19,6 +19,7 @@
 #include <FeaturesPlugin_Rotation.h>
 #include <FeaturesPlugin_Scale.h>
 #include <FeaturesPlugin_Symmetry.h>
+#include <FeaturesPlugin_Translation.h>
 #include <FeaturesPlugin_Union.h>
 #include <FeaturesPlugin_ValidatorTransform.h>
 #include <FeaturesPlugin_Validators.h>
@@ -105,6 +106,8 @@ FeaturePtr FeaturesPlugin_Plugin::createFeature(std::string theFeatureID)
     return FeaturePtr(new FeaturesPlugin_Symmetry);
   } else if (theFeatureID == FeaturesPlugin_Scale::ID()) {
     return FeaturePtr(new FeaturesPlugin_Scale);
+  } else if (theFeatureID == FeaturesPlugin_MultiTranslation::ID()) {
+    return FeaturePtr(new FeaturesPlugin_MultiTranslation);
   }
 
   // feature of such kind is not found
diff --git a/src/FeaturesPlugin/icons/multitranslation.png b/src/FeaturesPlugin/icons/multitranslation.png
new file mode 100644 (file)
index 0000000..d0d9c15
Binary files /dev/null and b/src/FeaturesPlugin/icons/multitranslation.png differ
diff --git a/src/FeaturesPlugin/multitranslation_widget.xml b/src/FeaturesPlugin/multitranslation_widget.xml
new file mode 100644 (file)
index 0000000..4c6bf66
--- /dev/null
@@ -0,0 +1,60 @@
+<!-- Copyright (C) 2014-201x CEA/DEN, EDF R&D -->
+
+<source>
+  <multi_selector id="main_objects"
+                  label="Main objects"
+                  icon=""
+                  tooltip="Select objects"
+                  type_choice="objects"
+                  concealment="true">
+    <validator id="FeaturesPlugin_ValidatorTransform"/>
+  </multi_selector>
+  <groupbox title="First direction">
+    <shape_selector id="axis_first_dir"
+                    icon="icons/Features/axis.png"
+                    label="Axis"
+                    tooltip="Select an edge for the first direction"
+                    shape_types="edge"
+                    default="">
+      <validator id="GeomValidators_ShapeType" parameters="line"/>
+    </shape_selector>
+    <doublevalue id="step_first_dir"
+                 label="Step"
+                 step="1.0"
+                 default="0"
+                 icon="icons/Features/dimension_v.png"
+                 tooltip="Step for the first direction">
+    </doublevalue>
+    <integervalue id="nb_first_dir"
+                  label="Nb copies"
+                  step="1"
+                  default="2"
+                  icon=""
+                  tooltip="Number of copies for the first direction">
+    </integervalue>
+  </groupbox>
+  <optionalbox id="use_second_dir" title="Second direction">
+    <shape_selector id="axis_second_dir"
+                    icon="icons/Features/axis.png"
+                    label="Axis"
+                    tooltip="Select an edge for the second direction"
+                    shape_types="edge"
+                    default="">
+      <validator id="GeomValidators_ShapeType" parameters="line"/>
+    </shape_selector>
+    <doublevalue id="step_second_dir"
+                 label="Step"
+                 step="1.0"
+                 default="0"
+                 icon="icons/Features/dimension_v.png"
+                 tooltip="Step for the second direction">
+    </doublevalue>
+    <integervalue id="nb_second_dir"
+                  label="Nb copies"
+                  step="1"
+                  default="2"
+                  icon=""
+                  tooltip="Number of copies for the second direction">
+    </integervalue>
+  </optionalbox>
+</source>
\ No newline at end of file
index 65488474bfc7e008b83aae9808fcc3057efcd8d0..07e9f9e067eeb2dddae9ad91ce5c030d88c9e295 100644 (file)
@@ -2,6 +2,11 @@
 
 <plugin>
   <workbench id="Features" document="Part">
+    <group id="Transformation">
+      <feature id="Scale" title="Scale" tooltip="Perform scale objects" icon="icons/Features/scale.png">
+        <source path="scale_widget.xml"/>
+      </feature>
+    </group>
     <group id="Extrusion">
       <feature id="Extrusion" title="Extrusion" tooltip="Create a solid by extrusion of a face" icon="icons/Features/extrusion.png">
           <source path="extrusion_widget.xml"/>
@@ -71,8 +76,8 @@
       <feature id="Symmetry" title="Symmetry" tooltip="Perform symmetry with respect to a point, an axis or a plane" icon="icons/Features/symmetry.png">
         <source path="symmetry_widget.xml"/>
       </feature>
-      <feature id="Scale" title="Scale" tooltip="Perform scale an objects" icon="icons/Features/scale.png">
-        <source path="scale_widget.xml"/>
+      <feature id="MultiTranslation" title="MultiTranslation" tooltip="Perform multi-translation objects" icon="icons/Features/multitranslation.png">
+        <source path="multitranslation_widget.xml"/>
       </feature>
     </group>
   </workbench>
index 4632e171ac9e3e16db947ac6599cd7cdfbec7b8e..7f678f5d320c38385036816822868868109f3fef 100644 (file)
@@ -2,6 +2,7 @@
 """
 
 from FeaturesAPI import addPlacement, addRotation, addScale, addSymmetry, addTranslation
+from FeaturesAPI import addMultiTranslation
 from FeaturesAPI import addExtrusion, addExtrusionCut, addExtrusionFuse
 from FeaturesAPI import addRevolution, addRevolutionCut, addRevolutionFuse
 from FeaturesAPI import addPipe