FeaturesAPI_Extrusion.h
FeaturesAPI_ExtrusionBoolean.h
FeaturesAPI_Intersection.h
+ FeaturesAPI_MultiTranslation.h
FeaturesAPI_Partition.h
FeaturesAPI_Pipe.h
FeaturesAPI_Placement.h
FeaturesAPI_Extrusion.cpp
FeaturesAPI_ExtrusionBoolean.cpp
FeaturesAPI_Intersection.cpp
+ FeaturesAPI_MultiTranslation.cpp
FeaturesAPI_Partition.cpp
FeaturesAPI_Pipe.cpp
FeaturesAPI_Placement.cpp
--- /dev/null
+// 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));
+}
--- /dev/null
+// 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_
FeaturesPlugin_Tools.h
FeaturesPlugin_Symmetry.h
FeaturesPlugin_Scale.h
+ FeaturesPlugin_MultiTranslation.h
)
SET(PROJECT_SOURCES
FeaturesPlugin_Tools.cpp
FeaturesPlugin_Symmetry.cpp
FeaturesPlugin_Scale.cpp
+ FeaturesPlugin_MultiTranslation.cpp
)
SET(XML_RESOURCES
union_widget.xml
symmetry_widget.xml
scale_widget.xml
+ multitranslation_widget.xml
)
SET(TEXT_RESOURCES
--- /dev/null
+// 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
--- /dev/null
+// 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
#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>
#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>
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
--- /dev/null
+<!-- 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
<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"/>
<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>
{
if (myMethodType == MethodType::BOX_DIM) {
if (myDx < Precision::Confusion()) {
- myError = "Box builder with dimensions :: Dx is null.";
+ myError = "Box builder with dimensions :: Dx is null or negative.";
return false;
} else if (myDy < Precision::Confusion()) {
- myError = "Box builder with dimensions :: Dy is null.";
+ myError = "Box builder with dimensions :: Dy is null or negative.";
return false;
} else if (myDz < Precision::Confusion()) {
- myError = "Box builder with dimensions :: Dz is null.";
+ myError = "Box builder with dimensions :: Dz is null or negative.";
return false;
}
} else if (myMethodType == MethodType::BOX_POINTS) {
if (!myFirstPoint.get()) {
- myError = "Box builder with points :: the first point is not a correct";
+ myError = "Box builder with points :: the first point is not correct.";
return false;
}
if (!mySecondPoint.get()) {
- myError = "Box builder with points :: the second point is not a correct";
+ myError = "Box builder with points :: the second point is not correct.";
return false;
}
if (myFirstPoint->distance(mySecondPoint) < Precision::Confusion()) {
fabs(aDiffY) < Precision::Confusion() ||
fabs(aDiffZ) < Precision::Confusion()) {
myError =
- "Box builder with points :: the points belong both to one of the OXY, OYZ or OZX planes";
+ "Box builder with points :: the points belong both to one of the OXY, OYZ or OZX planes.";
return false;
}
} else {
const double theHeight)
{
withAngle = false;
- //myBasePoint = theBasePoint;
myAxis = theAxis;
myRadius = theRadius;
myHeight = theHeight;
# Create a box with dimensions
try :
- box1 = shaperpy.makeBox(5.,15.,5.)
+ box1 = shaperpy.makeBox(10.,10.,10.)
+ print "box1 : ok"
except myExcept,ec:
- print ec.what()
+ print "box1 : ko (" + ec.what() + ")"
+
+try :
+ box2 = shaperpy.makeBox(0.,10.,10.)
+ print "box2 : ok"
+
+except myExcept,ec:
+ print "box2 : ko (" + ec.what() + ")"
+
+try :
+ box3 = shaperpy.makeBox(10.,0.,10.)
+ print "box3 : ok"
+
+except myExcept,ec:
+ print "box3 : ko (" + ec.what() + ")"
+
+try :
+ box4 = shaperpy.makeBox(10.,10.,0.)
+ print "box4 : ok"
+
+except myExcept,ec:
+ print "box4 : ko (" + ec.what() + ")"
+
+try :
+ box5 = shaperpy.makeBox(-10.,10.,10.)
+ print "box5 : ok"
+
+except myExcept,ec:
+ print "box5 : ko (" + ec.what() + ")"
+
+try :
+ box6 = shaperpy.makeBox(10.,-10.,10.)
+ print "box6 : ok"
+
+except myExcept,ec:
+ print "box6 : ko (" + ec.what() + ")"
+
+try :
+ box7 = shaperpy.makeBox(10.,10.,-10.)
+ print "box7 : ok"
+
+except myExcept,ec:
+ print "box7 : ko (" + ec.what() + ")"
# Create a box with two points defining the diagonal
try :
pnt1 = pnt(0.,0.,0.)
- pnt2 = pnt(10.,10.,10.)
- box2 = shaperpy.makeBox(pnt1,pnt2)
+ pnt2 = pnt(50.,50.,50.)
+ box8 = shaperpy.makeBox(pnt1,pnt2)
+ print "box8 : ok"
+
+except myExcept,ec:
+ print "box8 : ko (" + ec.what() + ")"
+
+try :
+ pnt1 = pnt(0.,0.,0.)
+ box9 = shaperpy.makeBox(pnt1,pnt1)
+ print "box9 : ok"
except myExcept,ec:
- print ec.what()
+ print "box9 : ko (" + ec.what() + ")"
-# Create a box with null dimensions
try :
- box3 = shaperpy.makeBox(0.,0.,0.)
+ pnt1 = pnt(0.,0.,0.)
+ pnt2 = pnt(0.,50.,50.)
+ box10 = shaperpy.makeBox(pnt1,pnt2)
+ print "box10 : ok"
except myExcept,ec:
- print ec.what()
+ print "box10 : ko (" + ec.what() + ")"
-# Create a box with negative dimensions
try :
- box4 = shaperpy.makeBox(-5.,15.,5.)
+ pnt1 = pnt(0.,0.,0.)
+ pnt2 = pnt(50.,0.,50.)
+ box11 = shaperpy.makeBox(pnt1,pnt2)
+ print "box11 : ok"
except myExcept,ec:
- print ec.what()
+ print "box11 : ko (" + ec.what() + ")"
-# Create a box with two same points
try :
pnt1 = pnt(0.,0.,0.)
- box5 = shaperpy.makeBox(pnt1,pnt1)
+ pnt2 = pnt(50.,50.,0.)
+ box12 = shaperpy.makeBox(pnt1,pnt2)
+ print "box12 : ok"
+
+except myExcept,ec:
+ print "box12 : ko (" + ec.what() + ")"
+
+try :
+ pnt1 = pnt(50.,50.,50.)
+ box13 = shaperpy.makeBox(pnt1,None)
+ print "box13 : ok"
except myExcept,ec:
- print ec.what()
\ No newline at end of file
+ print "box13 : ko (" + ec.what() + ")"
+
+try :
+ pnt2 = pnt(50.,50.,50.)
+ box14 = shaperpy.makeBox(None,pnt2)
+ print "box14 : ok"
+
+except myExcept,ec:
+ print "box14 : ko (" + ec.what() + ")"
+
# Create a box with dimensions
aSession.startOperation()
-aBox1 = model.addBox(aDocument, 10, 10, 10).result()
+aBox1 = model.addBox(aDocument, 10, 10, 10)
+model.testNbResults(aBox1, 1)
+model.testNbSubShapes(aBox1, GeomAPI_Shape.SOLID, [1])
+model.testNbSubShapes(aBox1, GeomAPI_Shape.FACE, [6])
+print "box1 : ok"
aSession.finishOperation()
-assert (aBox1 is not None)
-# Create a first point
aSession.startOperation()
-aFirstPoint = model.addPoint(aDocument, 0, 0, 0).result()
+aBox2 = model.addBox(aDocument, 0, 10, 10)
+model.testNbResults(aBox2, 0)
+print "box2 : ko (" + aBox2.feature().error() + ")"
aSession.finishOperation()
-# Create a second point
aSession.startOperation()
-aSecondPoint = model.addPoint(aDocument, 50, 50, 50).result()
+aBox3 = model.addBox(aDocument, 10, 0, 10)
+model.testNbResults(aBox3, 0)
+print "box3 : ko (" + aBox3.feature().error() + ")"
+aSession.finishOperation()
+
+aSession.startOperation()
+aBox4 = model.addBox(aDocument, 10, 10, 0)
+model.testNbResults(aBox4, 0)
+print "box4 : ko (" + aBox4.feature().error() + ")"
+aSession.finishOperation()
+
+aSession.startOperation()
+aBox5 = model.addBox(aDocument, -10, 10, 10)
+model.testNbResults(aBox5, 0)
+print "box5 : ko (" + aBox5.feature().error() + ")"
+aSession.finishOperation()
+
+aSession.startOperation()
+aBox6 = model.addBox(aDocument, 10, -10, 10)
+model.testNbResults(aBox6, 0)
+print "box6 : ko (" + aBox6.feature().error() + ")"
+aSession.finishOperation()
+
+aSession.startOperation()
+aBox7 = model.addBox(aDocument, 10, 10, -10)
+model.testNbResults(aBox7, 0)
+print "box7 : ko (" + aBox7.feature().error() + ")"
aSession.finishOperation()
# Create a box with 2 points
aSession.startOperation()
-aBox2 = model.addBox(aDocument, aFirstPoint, aSecondPoint).result()
+aPoint1 = model.addPoint(aDocument, 0, 0, 0).result()
+aPoint2 = model.addPoint(aDocument, 50, 50, 50).result()
+aBox8 = model.addBox(aDocument, aPoint1, aPoint2)
+model.testNbResults(aBox8, 1)
+model.testNbSubShapes(aBox8, GeomAPI_Shape.SOLID, [1])
+model.testNbSubShapes(aBox8, GeomAPI_Shape.FACE, [6])
+print "box8 : ok"
+aSession.finishOperation()
+
+aSession.startOperation()
+aPoint1 = model.addPoint(aDocument, 0, 0, 0).result()
+aBox9 = model.addBox(aDocument, aPoint1, aPoint1)
+model.testNbResults(aBox9, 0)
+print "box9 : ko (" + aBox9.feature().error() + ")"
+aSession.finishOperation()
+
+aSession.startOperation()
+aPoint1 = model.addPoint(aDocument, 0, 0, 0).result()
+aPoint2 = model.addPoint(aDocument, 0, 50, 50).result()
+aBox10 = model.addBox(aDocument, aPoint1, aPoint2)
+model.testNbResults(aBox10, 0)
+print "box10 : ko (" + aBox10.feature().error() + ")"
aSession.finishOperation()
-assert (aBox2 is not None)
-# Create a box with dimensions (error)
aSession.startOperation()
-aBox3 = model.addBox(aDocument, -10, 10, 10).result()
+aPoint1 = model.addPoint(aDocument, 0, 0, 0).result()
+aPoint2 = model.addPoint(aDocument, 50, 0, 50).result()
+aBox11 = model.addBox(aDocument, aPoint1, aPoint2)
+model.testNbResults(aBox11, 0)
+print "box11 : ko (" + aBox11.feature().error() + ")"
aSession.finishOperation()
-assert (aBox3 is not None)
-# Create a box with 2 points (error)
aSession.startOperation()
-aBox4 = model.addBox(aDocument, aFirstPoint, aFirstPoint).result()
+aPoint1 = model.addPoint(aDocument, 0, 0, 0).result()
+aPoint2 = model.addPoint(aDocument, 50, 50, 0).result()
+aBox12 = model.addBox(aDocument, aPoint1, aPoint2)
+model.testNbResults(aBox12, 0)
+print "box12 : ko (" + aBox12.feature().error() + ")"
aSession.finishOperation()
-assert (aBox4 is not None)
+aSession.startOperation()
+aPoint1 = model.selection("VERTEX", "point1")
+aPoint2 = model.addPoint(aDocument, 50, 50, 0).result()
+aBox13 = model.addBox(aDocument, aPoint1, aPoint2)
+model.testNbResults(aBox13, 0)
+print "box13 : ko (" + aBox13.feature().error() + ")"
+aSession.finishOperation()
+
+aSession.startOperation()
+aPoint1 = model.addPoint(aDocument, 0, 0, 0).result()
+aPoint2 = model.selection("VERTEX", "point2")
+aBox14 = model.addBox(aDocument, aPoint1, aPoint2)
+model.testNbResults(aBox14, 0)
+print "box14 : ko (" + aBox14.feature().error() + ")"
+aSession.finishOperation()
+
+aSession.startOperation()
+Sketch_1 = model.addSketch(aDocument, model.defaultPlane("XOY"))
+Sketch_2 = model.addSketch(aDocument, model.defaultPlane("YOZ"))
+SketchLine_1 = Sketch_1.addLine(20, 10, 40, 10)
+SketchLine_2 = Sketch_1.addLine(40, 10, 40, 20)
+SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
+SketchLine_3 = Sketch_1.addLine(40, 20, 20, 20)
+SketchLine_4 = Sketch_1.addLine(20, 20, 20, 10)
+SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
+SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_4.endPoint())
+SketchLine_5 = Sketch_2.addLine(20, 10, 40, 10)
+SketchLine_6 = Sketch_2.addLine(40, 10, 40, 20)
+SketchConstraintCoincidence_1 = Sketch_2.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
+SketchLine_7 = Sketch_2.addLine(40, 20, 20, 20)
+SketchLine_8 = Sketch_2.addLine(20, 20, 20, 10)
+SketchConstraintCoincidence_3 = Sketch_2.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint())
+SketchConstraintCoincidence_4 = Sketch_2.setCoincident(SketchLine_5.startPoint(), SketchLine_8.endPoint())
+aSession.finishOperation()
+
+aSession.startOperation()
+aBox15 = model.addBox(aDocument, model.selection("VERTEX", "Sketch_1/Vertex-SketchLine_1s-SketchLine_4e"),
+ model.selection("VERTEX", "Sketch_2/Vertex-SketchLine_7s-SketchLine_6e"))
+
+model.testNbResults(aBox15, 1)
+model.testNbSubShapes(aBox15, GeomAPI_Shape.SOLID, [1])
+model.testNbSubShapes(aBox15, GeomAPI_Shape.FACE, [6])
+print "box15 : ok"
+aSession.finishOperation()
+
+aSession.startOperation()
+Extrusion_1 = model.addExtrusion(aDocument, [model.selection("COMPOUND", "Sketch_1")], model.selection("EDGE", "PartSet/OZ"), 100, 0)
+Extrusion_2 = model.addExtrusion(aDocument, [model.selection("COMPOUND", "Sketch_2")], model.selection("EDGE", "PartSet/OX"), 100, 0)
+aBox16 = model.addBox(aDocument, model.selection("VERTEX", "Extrusion_1_1/Generated_Face_3&Extrusion_1_1/Generated_Face_2&Extrusion_1_1/To_Face_1"),
+ model.selection("VERTEX", "Extrusion_2_1/Generated_Face_2&Extrusion_2_1/Generated_Face_1&Extrusion_2_1/To_Face_1"))
+model.testNbResults(aBox16, 1)
+model.testNbSubShapes(aBox16, GeomAPI_Shape.SOLID, [1])
+model.testNbSubShapes(aBox16, GeomAPI_Shape.FACE, [6])
+print "box16 : ok"
+aSession.finishOperation()
+
+aSession.startOperation()
+Vertex_1 = model.addVertex(aDocument, [model.selection("VERTEX", "Sketch_1/Vertex-SketchLine_1s-SketchLine_4e")])
+Vertex_2 = model.addVertex(aDocument, [model.selection("VERTEX", "Sketch_2/Vertex-SketchLine_7s-SketchLine_6e")])
+aBox17 = model.addBox(aDocument, model.selection("VERTEX", "Vertex_1_1"), model.selection("VERTEX", "Vertex_2_1"))
+model.testNbResults(aBox17, 1)
+model.testNbSubShapes(aBox17, GeomAPI_Shape.SOLID, [1])
+model.testNbSubShapes(aBox17, GeomAPI_Shape.FACE, [6])
+print "box17 : ok"
+aSession.finishOperation()
#include <GeomAlgoAPI_PointBuilder.h>
#include <memory>
+#include <iostream>
//=================================================================================================
PrimitivesPlugin_Box::PrimitivesPlugin_Box() // Nothing to do during instantiation
// 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;
}
// 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;
}
// 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;
}
min = "0.0"
icon=""
tooltip="Dimension in X">
- <validator id="GeomValidators_Positive"/>
</doublevalue>
<doublevalue
id="dy"
min = "0.0"
icon=""
tooltip="Dimension in Y">
- <validator id="GeomValidators_Positive"/>
</doublevalue>
<doublevalue
id="dz"
min = "0.0"
icon=""
tooltip="Dimension in Z">
- <validator id="GeomValidators_Positive"/>
</doublevalue>
</box>
<box id="BoxByTwoPoints" title="By two points" icon="icons/Primitives/box_2pt_32x32.png">
icon="icons/Primitives/point.png"
tooltip="Select a first point"
shape_types="vertex">
- <validator id="GeomValidators_ShapeType" parameters="vertex"/>
</shape_selector>
<shape_selector id="SecondPoint"
label="Second point"
icon="icons/Primitives/point.png"
tooltip="Select a second point"
shape_types="vertex">
- <validator id="GeomValidators_ShapeType" parameters="vertex"/>
- <validator id="GeomValidators_DifferentShapes"/>
</shape_selector>
</box>
</toolbox>
"""
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