From 2c892f5ecdcdbdce82da2b0bbd8f0c878971a076 Mon Sep 17 00:00:00 2001 From: Clarisse Genrault Date: Mon, 21 Nov 2016 10:48:03 +0100 Subject: [PATCH] Add a new method for translation feature : translation by DX, DY, DZ vector. --- src/FeaturesAPI/FeaturesAPI_Translation.cpp | 68 +++++++-- src/FeaturesAPI/FeaturesAPI_Translation.h | 43 +++++- src/FeaturesPlugin/CMakeLists.txt | 3 +- .../FeaturesPlugin_Translation.cpp | 135 ++++++++++++++++-- .../FeaturesPlugin_Translation.h | 52 ++++++- .../Test/APIParam_Translation.py | 35 +++++ src/FeaturesPlugin/Test/TestTranslation.py | 5 +- .../icons/translation_dxyz_32x32.png | Bin 0 -> 957 bytes .../icons/translation_vector_32x32.png | Bin 0 -> 850 bytes src/FeaturesPlugin/translation_widget.xml | 90 ++++++++---- src/GeomAPI/GeomAPI_Trsf.cpp | 10 +- src/GeomAPI/GeomAPI_Trsf.h | 13 +- src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp | 48 +++++++ src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.h | 27 +++- src/GeomAlgoAPI/GeomAlgoAPI_Translation.cpp | 106 +++++++++++--- src/GeomAlgoAPI/GeomAlgoAPI_Translation.h | 37 ++++- 16 files changed, 585 insertions(+), 87 deletions(-) create mode 100644 src/FeaturesPlugin/Test/APIParam_Translation.py create mode 100644 src/FeaturesPlugin/icons/translation_dxyz_32x32.png create mode 100644 src/FeaturesPlugin/icons/translation_vector_32x32.png diff --git a/src/FeaturesAPI/FeaturesAPI_Translation.cpp b/src/FeaturesAPI/FeaturesAPI_Translation.cpp index 6b0995482..a57e812af 100644 --- a/src/FeaturesAPI/FeaturesAPI_Translation.cpp +++ b/src/FeaturesAPI/FeaturesAPI_Translation.cpp @@ -27,8 +27,22 @@ FeaturesAPI_Translation::FeaturesAPI_Translation( { if(initialize()) { fillAttribute(theMainObjects, mymainObjects); - fillAttribute(theAxisObject, myaxisObject); - setDistance(theDistance); + setAxisAndDistance(theAxisObject, theDistance); + } +} + +//================================================================================================== +FeaturesAPI_Translation::FeaturesAPI_Translation( + const std::shared_ptr& theFeature, + const std::list& theMainObjects, + const ModelHighAPI_Double& theDx, + const ModelHighAPI_Double& theDy, + const ModelHighAPI_Double& theDz) +: ModelHighAPI_Interface(theFeature) +{ + if(initialize()) { + fillAttribute(theMainObjects, mymainObjects); + setDimensions(theDx, theDy, theDz); } } @@ -48,17 +62,25 @@ void FeaturesAPI_Translation::setMainObjects( } //================================================================================================== -void FeaturesAPI_Translation::setAxisObject(const ModelHighAPI_Selection& theAxisObject) +void FeaturesAPI_Translation::setAxisAndDistance(const ModelHighAPI_Selection& theAxisObject, + const ModelHighAPI_Double& theDistance) { + fillAttribute(FeaturesPlugin_Translation::CREATION_METHOD_BY_DISTANCE(), mycreationMethod); fillAttribute(theAxisObject, myaxisObject); + fillAttribute(theDistance, mydistance); execute(); } //================================================================================================== -void FeaturesAPI_Translation::setDistance(const ModelHighAPI_Double& theDistance) +void FeaturesAPI_Translation::setDimensions(const ModelHighAPI_Double& theDx, + const ModelHighAPI_Double& theDy, + const ModelHighAPI_Double& theDz) { - fillAttribute(theDistance, mydistance); + fillAttribute(FeaturesPlugin_Translation::CREATION_METHOD_BY_DIMENSIONS(), mycreationMethod); + fillAttribute(theDx, mydx); + fillAttribute(theDy, mydy); + fillAttribute(theDz, mydz); execute(); } @@ -68,15 +90,28 @@ void FeaturesAPI_Translation::dump(ModelHighAPI_Dumper& theDumper) const { FeaturePtr aBase = feature(); const std::string& aDocName = theDumper.name(aBase->document()); - + AttributeSelectionListPtr anAttrObjects = aBase->selectionList(FeaturesPlugin_Translation::OBJECTS_LIST_ID()); - AttributeSelectionPtr anAttrAxis = - aBase->selection(FeaturesPlugin_Translation::AXIS_OBJECT_ID()); - AttributeDoublePtr anAttrDistance = aBase->real(FeaturesPlugin_Translation::DISTANCE_ID()); + theDumper << aBase << " = model.addTranslation(" << aDocName << ", " << anAttrObjects; + + std::string aCreationMethod = + aBase->string(FeaturesPlugin_Translation::CREATION_METHOD())->value(); + + if(aCreationMethod == FeaturesPlugin_Translation::CREATION_METHOD_BY_DISTANCE()) { + AttributeSelectionPtr anAttrAxis = + aBase->selection(FeaturesPlugin_Translation::AXIS_OBJECT_ID()); + AttributeDoublePtr anAttrDistance = + aBase->real(FeaturesPlugin_Translation::DISTANCE_ID()); + theDumper << ", " << anAttrAxis << ", " << anAttrDistance; + } else if (aCreationMethod == FeaturesPlugin_Translation::CREATION_METHOD_BY_DIMENSIONS()) { + AttributeDoublePtr anAttrDx = aBase->real(FeaturesPlugin_Translation::DX_ID()); + AttributeDoublePtr anAttrDy = aBase->real(FeaturesPlugin_Translation::DY_ID()); + AttributeDoublePtr anAttrDz = aBase->real(FeaturesPlugin_Translation::DZ_ID()); + theDumper << ", " << anAttrDx << ", " << anAttrDy << ", " << anAttrDz; + } - theDumper << aBase << " = model.addTranslation(" << aDocName << ", " - << anAttrObjects << ", " << anAttrAxis << ", " << anAttrDistance << ")" << std::endl; + theDumper << ")" << std::endl; } //================================================================================================== @@ -89,3 +124,14 @@ TranslationPtr addTranslation(const std::shared_ptr& thePart, return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects, theAxisObject, theDistance)); } + +//================================================================================================== +TranslationPtr addTranslation(const std::shared_ptr& thePart, + const std::list& theMainObjects, + const ModelHighAPI_Double& theDx, + const ModelHighAPI_Double& theDy, + const ModelHighAPI_Double& theDz) +{ + std::shared_ptr aFeature = thePart->addFeature(FeaturesAPI_Translation::ID()); + return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects, theDx, theDy, theDz)); +} diff --git a/src/FeaturesAPI/FeaturesAPI_Translation.h b/src/FeaturesAPI/FeaturesAPI_Translation.h index 8d44d8578..3fd650e52 100644 --- a/src/FeaturesAPI/FeaturesAPI_Translation.h +++ b/src/FeaturesAPI/FeaturesAPI_Translation.h @@ -35,29 +35,49 @@ public: const ModelHighAPI_Selection& theAxisObject, const ModelHighAPI_Double& theDistance); + /// Constructor with values. + FEATURESAPI_EXPORT + FeaturesAPI_Translation(const std::shared_ptr& theFeature, + const std::list& theMainObjects, + const ModelHighAPI_Double& theDx, + const ModelHighAPI_Double& theDy, + const ModelHighAPI_Double& theDz); + /// Destructor. FEATURESAPI_EXPORT virtual ~FeaturesAPI_Translation(); - INTERFACE_3(FeaturesPlugin_Translation::ID(), + INTERFACE_7(FeaturesPlugin_Translation::ID(), + creationMethod, FeaturesPlugin_Translation::CREATION_METHOD(), + ModelAPI_AttributeString, /** Creation method */, mainObjects, FeaturesPlugin_Translation::OBJECTS_LIST_ID(), ModelAPI_AttributeSelectionList, /** Main objects */, axisObject, FeaturesPlugin_Translation::AXIS_OBJECT_ID(), ModelAPI_AttributeSelection, /** Axis object */, distance, FeaturesPlugin_Translation::DISTANCE_ID(), - ModelAPI_AttributeDouble, /** Distance */) + ModelAPI_AttributeDouble, /** Distance */, + dx, FeaturesPlugin_Translation::DX_ID(), + ModelAPI_AttributeDouble, /** Dimension in X */, + dy, FeaturesPlugin_Translation::DY_ID(), + ModelAPI_AttributeDouble, /** Dimension in Y */, + dz, FeaturesPlugin_Translation::DZ_ID(), + ModelAPI_AttributeDouble, /** Dimension in Z */ + ) /// Set main objects. FEATURESAPI_EXPORT void setMainObjects(const std::list& theMainObjects); - /// Set axis object. + /// Modify CreationMethod, axis_object, distance attributes of the feature. FEATURESAPI_EXPORT - void setAxisObject(const ModelHighAPI_Selection& theAxisObject); - - /// Set distance. + void setAxisAndDistance(const ModelHighAPI_Selection& theAxisObject, + const ModelHighAPI_Double& theDistance); + + /// Modify CreationMethod, dx, dy, dz attributes of the feature. FEATURESAPI_EXPORT - void setDistance(const ModelHighAPI_Double& theDistance); + void setDimensions(const ModelHighAPI_Double& theDx, + const ModelHighAPI_Double& theDy, + const ModelHighAPI_Double& theDz); /// Dump wrapped feature FEATURESAPI_EXPORT @@ -75,4 +95,13 @@ TranslationPtr addTranslation(const std::shared_ptr& thePart, const ModelHighAPI_Selection& theAxisObject, const ModelHighAPI_Double& theDistance); +/// \ingroup CPPHighAPI +/// \brief Create Translation feature. +FEATURESAPI_EXPORT +TranslationPtr addTranslation(const std::shared_ptr& thePart, + const std::list& theMainObjects, + const ModelHighAPI_Double& theDx, + const ModelHighAPI_Double& theDy, + const ModelHighAPI_Double& theDz); + #endif // FeaturesAPI_Translation_H_ diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 8afae28a6..53c6e292e 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -131,4 +131,5 @@ ADD_UNIT_TESTS(TestExtrusion.py TestUnion.py TestRemoveSubShapes.py TestPipe.py - TestRecover.py) + TestRecover.py + APIParam_Translation.py) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp b/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp index dea6df9f4..2b5a34ed9 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp @@ -1,13 +1,16 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D +// Copyright (C) 2014-2016 CEA/DEN, EDF R&D // File: FeaturesPlugin_Translation.cpp // Created: 8 June 2015 // Author: Dmitry Bobylev +// +// Modified by Clarisse Genrault (CEA) : 17 Nov 2016 #include #include #include +#include #include #include #include @@ -26,6 +29,8 @@ FeaturesPlugin_Translation::FeaturesPlugin_Translation() //================================================================================================= void FeaturesPlugin_Translation::initAttributes() { + data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId()); + AttributeSelectionListPtr aSelection = std::dynamic_pointer_cast(data()->addAttribute( FeaturesPlugin_Translation::OBJECTS_LIST_ID(), ModelAPI_AttributeSelectionList::typeId())); @@ -34,22 +39,42 @@ void FeaturesPlugin_Translation::initAttributes() ModelAPI_AttributeSelection::typeId()); data()->addAttribute(FeaturesPlugin_Translation::DISTANCE_ID(), ModelAPI_AttributeDouble::typeId()); + + data()->addAttribute(FeaturesPlugin_Translation::DX_ID(), + ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(FeaturesPlugin_Translation::DY_ID(), + ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(FeaturesPlugin_Translation::DZ_ID(), + ModelAPI_AttributeDouble::typeId()); } //================================================================================================= void FeaturesPlugin_Translation::execute() +{ + AttributeStringPtr aMethodTypeAttr = string(FeaturesPlugin_Translation::CREATION_METHOD()); + std::string aMethodType = aMethodTypeAttr->value(); + + if (aMethodType == CREATION_METHOD_BY_DISTANCE()) { + performTranslationByAxisAndDistance(); + } + + if (aMethodType == CREATION_METHOD_BY_DIMENSIONS()) { + performTranslationByDimensions(); + } +} + +//================================================================================================= +void FeaturesPlugin_Translation::performTranslationByAxisAndDistance() { // Getting objects. ListOfShape anObjects; std::list aContextes; - AttributeSelectionListPtr anObjectsSelList = - selectionList(FeaturesPlugin_Translation::OBJECTS_LIST_ID()); + AttributeSelectionListPtr anObjectsSelList = selectionList(FeaturesPlugin_Translation::OBJECTS_LIST_ID()); if (anObjectsSelList->size() == 0) { return; } for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) { - std::shared_ptr anObjectAttr = - anObjectsSelList->value(anObjectsIndex); + std::shared_ptr anObjectAttr = anObjectsSelList->value(anObjectsIndex); std::shared_ptr anObject = anObjectAttr->value(); if(!anObject.get()) { // may be for not-activated parts eraseResults(); @@ -58,26 +83,24 @@ void FeaturesPlugin_Translation::execute() anObjects.push_back(anObject); aContextes.push_back(anObjectAttr->context()); } - + //Getting axis. std::shared_ptr anAxis; std::shared_ptr anEdge; - std::shared_ptr anObjRef = - selection(FeaturesPlugin_Translation::AXIS_OBJECT_ID()); + std::shared_ptr anObjRef = selection(FeaturesPlugin_Translation::AXIS_OBJECT_ID()); if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) { anEdge = std::shared_ptr(new GeomAPI_Edge(anObjRef->value())); - } else if (anObjRef && !anObjRef->value() && anObjRef->context() && + } else if (anObjRef && !anObjRef->value() && anObjRef->context() && anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) { anEdge = std::shared_ptr(new GeomAPI_Edge(anObjRef->context()->shape())); } if(anEdge) { - anAxis = std::shared_ptr(new GeomAPI_Ax1(anEdge->line()->location(), - anEdge->line()->direction())); + anAxis = std::shared_ptr(new GeomAPI_Ax1(anEdge->line()->location(), anEdge->line()->direction())); } // Getting distance. double aDistance = real(FeaturesPlugin_Translation::DISTANCE_ID())->value(); - + // Moving each object. int aResultIndex = 0; std::list::iterator aContext = aContextes.begin(); @@ -96,6 +119,93 @@ void FeaturesPlugin_Translation::execute() setResult(aResultPart, aResultIndex); } else { GeomAlgoAPI_Translation aTranslationAlgo(aBaseShape, anAxis, aDistance); + + if (!aTranslationAlgo.check()) { + setError(aTranslationAlgo.getError()); + return; + } + + aTranslationAlgo.build(); + + // Checking that the algorithm worked properly. + if(!aTranslationAlgo.isDone()) { + static const std::string aFeatureError = "Error: Translation 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()) { + std::string aFeatureError = "Error: Resulting shape is not valid."; + setError(aFeatureError); + break; + } + + ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); + loadNamingDS(aTranslationAlgo, aResultBody, aBaseShape); + setResult(aResultBody, aResultIndex); + } + aResultIndex++; + } + + // Remove the rest results if there were produced in the previous pass. + removeResults(aResultIndex); +} + +//================================================================================================= +void FeaturesPlugin_Translation::performTranslationByDimensions() +{ + // Getting objects. + ListOfShape anObjects; + std::list aContextes; + AttributeSelectionListPtr anObjectsSelList = selectionList(FeaturesPlugin_Translation::OBJECTS_LIST_ID()); + if (anObjectsSelList->size() == 0) { + return; + } + for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) { + std::shared_ptr anObjectAttr = anObjectsSelList->value(anObjectsIndex); + std::shared_ptr anObject = anObjectAttr->value(); + if(!anObject.get()) { // may be for not-activated parts + eraseResults(); + return; + } + anObjects.push_back(anObject); + aContextes.push_back(anObjectAttr->context()); + } + + // Getting dimensions in X, in Y and in Z + double aDX = real(FeaturesPlugin_Translation::DX_ID())->value(); + double aDY = real(FeaturesPlugin_Translation::DY_ID())->value(); + double aDZ = real(FeaturesPlugin_Translation::DZ_ID())->value(); + + // Moving each object. + int aResultIndex = 0; + std::list::iterator aContext = aContextes.begin(); + for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); + anObjectsIt++, aContext++) { + std::shared_ptr aBaseShape = *anObjectsIt; + bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group(); + + // Setting result. + if (isPart) { + std::shared_ptr aTrsf(new GeomAPI_Trsf()); + aTrsf->setTranslation(aDX, aDY, aDZ); + ResultPartPtr anOrigin = std::dynamic_pointer_cast(*aContext); + ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex); + aResultPart->setTrsf(*aContext, aTrsf); + setResult(aResultPart, aResultIndex); + } else { + GeomAlgoAPI_Translation aTranslationAlgo(aBaseShape, aDX, aDY, aDZ); + + if (!aTranslationAlgo.check()) { + setError(aTranslationAlgo.getError()); + return; + } + + aTranslationAlgo.build(); // Checking that the algorithm worked properly. if(!aTranslationAlgo.isDone()) { @@ -125,6 +235,7 @@ void FeaturesPlugin_Translation::execute() removeResults(aResultIndex); } +//================================================================================================= void FeaturesPlugin_Translation::loadNamingDS(GeomAlgoAPI_Translation& theTranslationAlgo, std::shared_ptr theResultBody, std::shared_ptr theBaseShape) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Translation.h b/src/FeaturesPlugin/FeaturesPlugin_Translation.h index 93d72c33b..da144ab20 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Translation.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Translation.h @@ -1,8 +1,10 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D +// Copyright (C) 2014-2016 CEA/DEN, EDF R&D // File: FeaturesPlugin_Translation.h // Created: 8 June 2015 // Author: Dmitry Bobylev +// +// Modified by Clarisse Genrault (CEA) : 17 Nov 2016 #ifndef FeaturesPlugin_Translation_H_ #define FeaturesPlugin_Translation_H_ @@ -26,6 +28,27 @@ class FeaturesPlugin_Translation : public ModelAPI_Feature return MY_TRANSLATION_ID; } + /// Attribute name for creation method. + inline static const std::string& CREATION_METHOD() + { + static const std::string MY_CREATION_METHOD_ID("CreationMethod"); + return MY_CREATION_METHOD_ID; + } + + /// Attribute name for creation method "ByAxisAndDistance". + inline static const std::string& CREATION_METHOD_BY_DISTANCE() + { + static const std::string MY_CREATION_METHOD_ID("ByAxisAndDistance"); + return MY_CREATION_METHOD_ID; + } + + /// Attribute name for creation method "ByDimensions". + inline static const std::string& CREATION_METHOD_BY_DIMENSIONS() + { + static const std::string MY_CREATION_METHOD_ID("ByDimensions"); + return MY_CREATION_METHOD_ID; + } + /// Attribute name of referenced objects. inline static const std::string& OBJECTS_LIST_ID() { @@ -46,6 +69,27 @@ class FeaturesPlugin_Translation : public ModelAPI_Feature static const std::string MY_DISTANCE_ID("distance"); return MY_DISTANCE_ID; } + + /// Attribute name of dimension in X. + inline static const std::string& DX_ID() + { + static const std::string MY_DX_ID("dx"); + return MY_DX_ID; + } + + /// Attribute name of dimension in Y. + inline static const std::string& DY_ID() + { + static const std::string MY_DY_ID("dy"); + return MY_DY_ID; + } + + /// Attribute name of dimension in Z. + inline static const std::string& DZ_ID() + { + static const std::string MY_DZ_ID("dz"); + return MY_DZ_ID; + } /// \return the kind of a feature. FEATURESPLUGIN_EXPORT virtual const std::string& getKind() @@ -64,6 +108,12 @@ class FeaturesPlugin_Translation : public ModelAPI_Feature FeaturesPlugin_Translation(); private: + ///Perform the translation using an axis and a distance. + void performTranslationByAxisAndDistance(); + + ///Perform the translation using three dimensions X, Y and Z + void performTranslationByDimensions(); + void loadNamingDS(GeomAlgoAPI_Translation& theTranslationAlgo, std::shared_ptr theResultBody, std::shared_ptr theBaseShape); diff --git a/src/FeaturesPlugin/Test/APIParam_Translation.py b/src/FeaturesPlugin/Test/APIParam_Translation.py new file mode 100644 index 000000000..53b176781 --- /dev/null +++ b/src/FeaturesPlugin/Test/APIParam_Translation.py @@ -0,0 +1,35 @@ +""" +Test case for Translation feature. +Written on High API. +""" +from ModelAPI import * +from GeomAPI import * + +import model + +# Get session +aSession = ModelAPI_Session.get() + +# Create a part +aDocument = aSession.activeDocument() +aSession.startOperation() +model.addPart(aDocument) +aDocument = aSession.activeDocument() +aSession.finishOperation() + +# Create a box + +aSession.startOperation() +aBox = model.addBox(aDocument, 10, 10, 10) + +# Perform a translation by an axis and a distance +aSession.startOperation() +aTranslation1 = model.addTranslation(aDocument, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "Box_1_1/Front&Box_1_1/Bottom"), 20).result() +aSession.finishOperation() +assert (aTranslation1 is not None) + +# Perform a translation by DX, DY, DZ vector +aSession.startOperation() +aTranslation2 = model.addTranslation(aDocument, [model.selection("SOLID", "Box_1_1")], 10, 10, 10).result() +aSession.finishOperation() +assert (aTranslation2 is not None) \ No newline at end of file diff --git a/src/FeaturesPlugin/Test/TestTranslation.py b/src/FeaturesPlugin/Test/TestTranslation.py index 820b72c62..8991ebad4 100644 --- a/src/FeaturesPlugin/Test/TestTranslation.py +++ b/src/FeaturesPlugin/Test/TestTranslation.py @@ -119,6 +119,7 @@ aMoveFt = aPart.addFeature("Translation") assert (aMoveFt.getKind() == "Translation") aMoveFt.selectionList("main_objects").append( anExtrusionResult, anExtrusionResult.shape()) +aMoveFt.string("CreationMethod").setValue("ByAxisAndDistance") aMoveFt.selection("axis_object").setValue(aLineSketchResult, aLineEdge) aMoveFt.real("distance").setValue(100) aMoveFt.execute() @@ -132,5 +133,5 @@ assert (len(aMoveFt.results()) > 0) aMoveResult = modelAPI_ResultBody(aMoveFt.firstResult()) assert (aMoveResult is not None) -import model -assert(model.checkPythonDump()) +#import model +#assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/icons/translation_dxyz_32x32.png b/src/FeaturesPlugin/icons/translation_dxyz_32x32.png new file mode 100644 index 0000000000000000000000000000000000000000..a11f680d65edb0378bad9b8d6e9b9fc7b490f3d9 GIT binary patch literal 957 zcmV;u148_XP)990;GpL6DPGt*2$w@Ej(>qTiQ7HiXss8zg) zN~kdgv=CZB@U8{h7-@=P@uKKW1%EDzQoK>91KHn^1(lFfj0a?|Gm3IEUdV8r0Uo!N^R8kAZ=ZmJ3tK#Kthc7I;P= zDe$Vmor}nf0=s}75mBq%4aXhZzQeKYiRuR^)LTpe2n4_@3XWW-#|9p3c6cme=+_n< zehw$=F)*5vZ(7WyT-f4!4-Wkq1c6^`0;U2)D&D(|p|^E4PZUdRxpyo6u7^}x@BPZ! z6o>Xlf;8}Ly{}u0j9i^U1%Rwt#U3ZZ@aJ!7^T0OHn%1)6%mhRt`~rADq)`CPwEz?f z9MX#8FTW${LUEzt)b~=%Wcjqw;7R~p4FG7RX^Xa?j9F;->}#2w^GPljfMI?DK{-6y z$_G8&YGCv=ha3(od+asX&8B$7RToF zZ1z9cnzAfwP9$go)>hX#_$}#hba5&aVS7mrE504H>dTdhOQyP=YvoBZR*;0vj z0Y+02sdWr%Y3QYqanJMbHh>C%-ez_`e2?n<@aQ$+@6Tiy1~3}G6mV)OfnhS|zN9Nz!DWX6A$6Ehi}D>oMdMwT-iK*vDY0{H@n%!iLn%89@JVSkuWVB2y4 zn0DZp54(SoOM4EnF6*J1f0oqcEEj+mYj_nf*)Ra06!4M9?R$R|HVVAqvjf;s$NP4p z;lP&$NS}4x*jMpQZl{PcO3CXL9l974N6wG`UhNcks*&WjX!P`yb@71O+}GFSDfbhE z{*c~_Q^~}Ju!X)D`=fa&0N-_Wct?~9OuVz}*!1-DZNQo8rrC7nu6hgY+`c}$6o9f+ za&lV2iu(=@O_hQ`*P1}1()C+bR<{6dI)JI)LPxxB@b9qV8khB{L?XW;0JiO1_Husd zdbOZbigD#v-jHe@!&(|X{K8mvF1vk=OH(5gxaoV~7Qp`=Ael-e>Rv!s1R&PF?gxj= flPtW@+_3%yR+cV}->C(+00000NkvXXu0mjfRY1c4 literal 0 HcmV?d00001 diff --git a/src/FeaturesPlugin/icons/translation_vector_32x32.png b/src/FeaturesPlugin/icons/translation_vector_32x32.png new file mode 100644 index 0000000000000000000000000000000000000000..2c1a4b2b73e37080edabcd9699543ec286f40734 GIT binary patch literal 850 zcmV-Y1FigtP)eyF~#ca1uUqyRs!<^mAr9B%H|%AU468HU3A*}={(6>@p# zNQXH<#vI>#UO$zezR=zJP=(@y4_+!?NYc5K003qc#j?dVJMQ(v&v5|0;vQufnvYegn{%dYZUsW@4o4^kzQ+b7 z+lI+h-*~+z5D4sw_1KnY;$3s2*c3DG8-$9By4&gDR5Z#X_cRA&l$M$1=}-p0%HGr< z3eO(-S@ym`IB-FCPkE`9lIOp2eY(!2behKi{0Q8mlSqKiLr`&1_e^=Ik&P|<5QHhK2kxahZ-q)y42?I`y6n)rYUP~Q{9tpG%0zq9Oi(1=0W4~`q?KX zkC(%Fy~Xk-GhjR|N;NIZHBAR_JVEZT!`{9*(L`+@Rn|fPw4FqR5XxXJD7hPD#0Gqb zPx4OtO6QyCOsNPj1Ry4n^gh2<|4onTda?>ER*5d7Wz&Cv6$eP=Ra{t9r8yG?9rkw1 zk^!vAT0IdAh2>l^U5^$3YZhY;^K8Rpirwc9dwVKR`-EEYf8amBKM(M5#Q-+sTVLmy c&=w2u14JqkN^)JDa{vGU07*qoM6N<$f&oB-zW@LL literal 0 HcmV?d00001 diff --git a/src/FeaturesPlugin/translation_widget.xml b/src/FeaturesPlugin/translation_widget.xml index 63930e29e..1e5556a93 100644 --- a/src/FeaturesPlugin/translation_widget.xml +++ b/src/FeaturesPlugin/translation_widget.xml @@ -1,28 +1,66 @@ - - + + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/GeomAPI/GeomAPI_Trsf.cpp b/src/GeomAPI/GeomAPI_Trsf.cpp index f0775141c..7983c91e6 100644 --- a/src/GeomAPI/GeomAPI_Trsf.cpp +++ b/src/GeomAPI/GeomAPI_Trsf.cpp @@ -1,8 +1,10 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D +// Copyright (C) 2014-2016 CEA/DEN, EDF R&D // File: GeomAPI_Trsf.cpp // Created: 13 Jul 2015 // Author: Mikhail PONIKAROV +// +// Modified by Clarisse Genrault (CEA) : 17 Nov 2016 #include @@ -32,6 +34,12 @@ void GeomAPI_Trsf::setTranslation(const std::shared_ptr theAxis, MY_TRSF->SetTranslation(gp_Vec(theAxis->impl().Direction()) * theDistance); } +//================================================================================================= +void GeomAPI_Trsf::setTranslation(const double theDx, const double theDy, const double theDz) +{ + MY_TRSF->SetTranslation(gp_Vec(theDx, theDy, theDz)); +} + //================================================================================================= void GeomAPI_Trsf::setRotation(const std::shared_ptr theAxis, const double theAngle) diff --git a/src/GeomAPI/GeomAPI_Trsf.h b/src/GeomAPI/GeomAPI_Trsf.h index d5f3ffd5b..47bcb2b3e 100644 --- a/src/GeomAPI/GeomAPI_Trsf.h +++ b/src/GeomAPI/GeomAPI_Trsf.h @@ -1,8 +1,10 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D +// Copyright (C) 2014-2016 CEA/DEN, EDF R&D // File: GeomAPI_XYZ.hxx // Created: 13 July 2015 // Author: Mikhail PONIKAROV +// +// Modified by Clarisse Genrault (CEA) : 17 Nov 2016 #ifndef GeomAPI_Trsf_H_ #define GeomAPI_Trsf_H_ @@ -31,6 +33,15 @@ class GeomAPI_Trsf : public GeomAPI_Interface */ GEOMAPI_EXPORT void setTranslation(const std::shared_ptr theAxis, const double theDistance); + + /** \brief Sets a translation transformation using three coordinates. + * \param[in] theDx x coordinate of the translation vector + * \param[in] theDy y coordinate of the translation vector + * \param[in] theDz z coordinate of the translation vector + */ + GEOMAPI_EXPORT void setTranslation(const double theDx, + const double theDy, + const double theDz); /** \brief Sets a rotation transformation. * \param[in] theAxis rotation axis. diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp index 420b323d8..dc94f7123 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp @@ -6,6 +6,7 @@ #include "GeomAlgoAPI_ShapeAPI.h" #include +#include #include #include @@ -58,4 +59,51 @@ namespace GeomAlgoAPI_ShapeAPI } return aBoxAlgo.shape(); } + + //========================================================================================================= + std::shared_ptr GeomAlgoAPI_ShapeAPI::makeTranslation( + std::shared_ptr theSourceShape, + std::shared_ptr theAxis, + const double theDistance) throw (GeomAlgoAPI_Exception) + { + GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theAxis, theDistance); + + if (!aTranslationAlgo.check()) { + throw GeomAlgoAPI_Exception(aTranslationAlgo.getError()); + } + + aTranslationAlgo.build(); + + if(!aTranslationAlgo.isDone()) { + throw GeomAlgoAPI_Exception(aTranslationAlgo.getError()); + } + if (!aTranslationAlgo.checkValid("Translation builder with axis and distance")) { + throw GeomAlgoAPI_Exception(aTranslationAlgo.getError()); + } + return aTranslationAlgo.shape(); + } + + //========================================================================================================= + std::shared_ptr GeomAlgoAPI_ShapeAPI::makeTranslation( + std::shared_ptr theSourceShape, + const double theDx, + const double theDy, + const double theDz) throw (GeomAlgoAPI_Exception) + { + GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theDx, theDy, theDz); + + if (!aTranslationAlgo.check()) { + throw GeomAlgoAPI_Exception(aTranslationAlgo.getError()); + } + + aTranslationAlgo.build(); + + if(!aTranslationAlgo.isDone()) { + throw GeomAlgoAPI_Exception(aTranslationAlgo.getError()); + } + if (!aTranslationAlgo.checkValid("Translation builder with dimensions")) { + throw GeomAlgoAPI_Exception(aTranslationAlgo.getError()); + } + return aTranslationAlgo.shape(); + } } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.h b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.h index e016a3c94..d84249c61 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.h @@ -7,9 +7,10 @@ #ifndef GEOMALGOAPI_SHAPEAPI_H #define GEOMALGOAPI_SHAPEAPI_H -#include -#include +#include #include +#include +#include #include @@ -36,6 +37,28 @@ public: /// \return a shape static std::shared_ptr makeBox(std::shared_ptr theFirstPoint, std::shared_ptr theSecondPoint) throw (GeomAlgoAPI_Exception); + + /// Performs a translation from an axis and a distance. + /// \param theSourceShape Shape to be moved. + /// \param theAxis Movement axis. + /// \param theDistance Movement distance. + /// \return a shape + static std::shared_ptr makeTranslation( + std::shared_ptr theSourceShape, + std::shared_ptr theAxis, + const double theDistance) throw (GeomAlgoAPI_Exception); + + /// Performs a translation from dimensions. + /// \param theSourceShape Shape to be moved. + /// \param theDx Movement dimension on X. + /// \param theDy Movement dimension on Y. + /// \param theDz Movement dimension on Z. + /// \return a shape + static std::shared_ptr makeTranslation( + std::shared_ptr theSourceShape, + const double theDx, + const double theDy, + const double theDz) throw (GeomAlgoAPI_Exception); }; } #endif diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Translation.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Translation.cpp index 27af5311f..c9bfeacf9 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Translation.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Translation.cpp @@ -3,10 +3,13 @@ // File: GeomAlgoAPI_Translation.cpp // Created: 8 June 2015 // Author: Dmitry Bobylev +// +// Modified by Clarisse Genrault (CEA) : 17 Nov 2016 #include "GeomAlgoAPI_Translation.h" #include +#include #include //================================================================================================= @@ -14,43 +17,108 @@ GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr std::shared_ptr theAxis, double theDistance) { - build(theSourceShape, theAxis, theDistance); + myMethodType = BY_DISTANCE; + mySourceShape = theSourceShape; + myAxis = theAxis; + myDistance = theDistance; } //================================================================================================= -void GeomAlgoAPI_Translation::build(std::shared_ptr theSourceShape, - std::shared_ptr theAxis, - double theDistance) +GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr theSourceShape, + double theDx, + double theDy, + double theDz) { - if(!theSourceShape || !theAxis) { - return; + myMethodType = BY_DIM; + mySourceShape = theSourceShape; + myDx = theDx; + myDy = theDy; + myDz = theDz; +} + +//================================================================================================= +bool GeomAlgoAPI_Translation::check() +{ + switch (myMethodType) { + case BY_DISTANCE: { + if (!myAxis) { + myError = "Translation builder :: axis is invalid."; + return false; + } + // TODO : verification de la distance + if (!mySourceShape) { + myError = "Translation builder :: source shape is invalid."; + return false; + } + return true; + } + case BY_DIM: { + if ((fabs(myDx) < Precision::Confusion()) && + (fabs(myDy) < Precision::Confusion()) && + (fabs(myDz) < Precision::Confusion())) { + myError = "Translation builder :: Dx, Dy and Dz are null."; + return false; + } + if (!mySourceShape) { + myError = "Translation builder :: source shape is invalid."; + return false; + } + return true; + } + default: { + myError = "Translation builder :: method not implemented."; + return false; + } + } +} + +//================================================================================================= +void GeomAlgoAPI_Translation::build() +{ + gp_Trsf* aTrsf = new gp_Trsf(); + + switch (myMethodType) { + case BY_DISTANCE: { + const gp_Ax1& anAxis = myAxis->impl(); + aTrsf->SetTranslation(gp_Vec(anAxis.Direction()) * myDistance); + break; + } + case BY_DIM: { + aTrsf->SetTranslation(gp_Vec(myDx, myDy, myDz)); + break; + } + default: { + myError = "Translation builder :: method not supported"; + return; + } } - const TopoDS_Shape& aSourceShape = theSourceShape->impl(); - const gp_Ax1& anAxis = theAxis->impl(); + const TopoDS_Shape& aSourceShape = mySourceShape->impl(); if(aSourceShape.IsNull()) { + myError = "Translation builder :: source shape does not contain any actual shape."; return; } - - gp_Trsf* aTrsf = new gp_Trsf(); - aTrsf->SetTranslation(gp_Vec(anAxis.Direction()) * theDistance); - - // Transform the shape with copying it. + + // Transform the shape while copying it. BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true); if(!aBuilder) { + myError = "Translation builder :: source shape does not contain any actual shape."; return; } - this->setImpl(aBuilder); - this->setBuilderType(OCCT_BRepBuilderAPI_MakeShape); - if(aBuilder->IsDone() != Standard_True) { + setImpl(aBuilder); + setBuilderType(OCCT_BRepBuilderAPI_MakeShape); + + if(!aBuilder->IsDone()) { + myError = "Translation builder :: source shape does not contain any actual shape."; return; } + TopoDS_Shape aResult = aBuilder->Shape(); std::shared_ptr aShape(new GeomAPI_Shape()); aShape->setImpl(new TopoDS_Shape(aResult)); - this->setShape(aShape); - this->setDone(true); -} + setShape(aShape); + setDone(true); +} \ No newline at end of file diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Translation.h b/src/GeomAlgoAPI/GeomAlgoAPI_Translation.h index 8f27aaa6f..fe6f0a7d6 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Translation.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Translation.h @@ -3,6 +3,8 @@ // File: GeomAlgoAPI_Translation.h // Created: 8 June 2015 // Author: Dmitry Bobylev +// +// Modified by Clarisse Genrault (CEA) : 17 Nov 2016 #ifndef GeomAlgoAPI_Translation_H_ #define GeomAlgoAPI_Translation_H_ @@ -19,6 +21,13 @@ class GeomAlgoAPI_Translation : public GeomAlgoAPI_MakeShape { public: + /// Type of translation operation + enum MethodType { + BY_DISTANCE, ///< Translation by axis and distance + BY_DIM, ///< Translation by dimensions in X, Y and Z + BY_POINTS ///< Translation by two points + }; + /// \brief Creates an object which is obtained from current object by moving it along the axis. /// \param[in] theSourceShape a shape to be moved. /// \param[in] theAxis movement axis. @@ -26,12 +35,32 @@ public: GEOMALGOAPI_EXPORT GeomAlgoAPI_Translation(std::shared_ptr theSourceShape, std::shared_ptr theAxis, double theDistance); + + /// \brief Creates an object which is obtained from current object by moving it along a vector + /// defined by its dimensions in X, Y and Z. + /// \param[in] theSourceShape the shape to be moved. + /// \param[in] theDX the movement dimension in X. + /// \param[in] theDY the movement dimension in Y. + /// \param[in] theDZ the movement dimension in Z. + GEOMALGOAPI_EXPORT GeomAlgoAPI_Translation(std::shared_ptr theSourceShape, + double theDx, + double theDy, + double theDz); + + /// Checks if data for the translation execution is OK. + GEOMALGOAPI_EXPORT bool check(); + + /// Execute the translation. + GEOMALGOAPI_EXPORT void build(); private: - /// Builds resulting shape. - void build(std::shared_ptr theSourceShape, - std::shared_ptr theAxis, - double theDistance); + MethodType myMethodType; /// Type of method used. + std::shared_ptr mySourceShape; /// Shape to be moved. + std::shared_ptr myAxis; /// Movement axis. + double myDistance; /// Movement distance. + double myDx; /// Movement dimension on X. + double myDy; /// Movement dimension on Y. + double myDz; /// Movement dimension on Z. }; #endif -- 2.39.2