{
if(initialize()) {
fillAttribute(theMainObjects, mymainObjects);
- fillAttribute(theAxisObject, myaxisObject);
- setDistance(theDistance);
+ setAxisAndDistance(theAxisObject, theDistance);
+ }
+}
+
+//==================================================================================================
+FeaturesAPI_Translation::FeaturesAPI_Translation(
+ const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const std::list<ModelHighAPI_Selection>& 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);
}
}
}
//==================================================================================================
-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();
}
{
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;
}
//==================================================================================================
return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects,
theAxisObject, theDistance));
}
+
+//==================================================================================================
+TranslationPtr addTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
+ const std::list<ModelHighAPI_Selection>& theMainObjects,
+ const ModelHighAPI_Double& theDx,
+ const ModelHighAPI_Double& theDy,
+ const ModelHighAPI_Double& theDz)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Translation::ID());
+ return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects, theDx, theDy, theDz));
+}
const ModelHighAPI_Selection& theAxisObject,
const ModelHighAPI_Double& theDistance);
+ /// Constructor with values.
+ FEATURESAPI_EXPORT
+ FeaturesAPI_Translation(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const std::list<ModelHighAPI_Selection>& 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<ModelHighAPI_Selection>& 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
const ModelHighAPI_Selection& theAxisObject,
const ModelHighAPI_Double& theDistance);
+/// \ingroup CPPHighAPI
+/// \brief Create Translation feature.
+FEATURESAPI_EXPORT
+TranslationPtr addTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
+ const std::list<ModelHighAPI_Selection>& theMainObjects,
+ const ModelHighAPI_Double& theDx,
+ const ModelHighAPI_Double& theDy,
+ const ModelHighAPI_Double& theDz);
+
#endif // FeaturesAPI_Translation_H_
TestUnion.py
TestRemoveSubShapes.py
TestPipe.py
- TestRecover.py)
+ TestRecover.py
+ APIParam_Translation.py)
-// 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 <FeaturesPlugin_Translation.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeString.h>
#include <ModelAPI_BodyBuilder.h>
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_ResultPart.h>
//=================================================================================================
void FeaturesPlugin_Translation::initAttributes()
{
+ data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
+
AttributeSelectionListPtr aSelection =
std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->addAttribute(
FeaturesPlugin_Translation::OBJECTS_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
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<ResultPtr> 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<ModelAPI_AttributeSelection> anObjectAttr =
- anObjectsSelList->value(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();
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_Translation::AXIS_OBJECT_ID());
+ std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = selection(FeaturesPlugin_Translation::AXIS_OBJECT_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() &&
+ } 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()));
+ anAxis = std::shared_ptr<GeomAPI_Ax1>(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<ResultPtr>::iterator aContext = aContextes.begin();
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<ResultPtr> 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<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 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<ResultPtr>::iterator aContext = aContextes.begin();
+ for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end();
+ anObjectsIt++, aContext++) {
+ std::shared_ptr<GeomAPI_Shape> aBaseShape = *anObjectsIt;
+ bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group();
+
+ // Setting result.
+ if (isPart) {
+ std::shared_ptr<GeomAPI_Trsf> aTrsf(new GeomAPI_Trsf());
+ aTrsf->setTranslation(aDX, aDY, aDZ);
+ ResultPartPtr anOrigin = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*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()) {
removeResults(aResultIndex);
}
+//=================================================================================================
void FeaturesPlugin_Translation::loadNamingDS(GeomAlgoAPI_Translation& theTranslationAlgo,
std::shared_ptr<ModelAPI_ResultBody> theResultBody,
std::shared_ptr<GeomAPI_Shape> theBaseShape)
-// 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_
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()
{
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()
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<ModelAPI_ResultBody> theResultBody,
std::shared_ptr<GeomAPI_Shape> theBaseShape);
--- /dev/null
+"""
+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
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()
aMoveResult = modelAPI_ResultBody(aMoveFt.firstResult())
assert (aMoveResult is not None)
-import model
-assert(model.checkPythonDump())
+#import model
+#assert(model.checkPythonDump())
-<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
+<!-- Copyright (C) 2014-2016 CEA/DEN, EDF R&D -->
+<!-- Modified by Clarisse Genrault (CEA) : 17 Nov 2016 -->
<source>
- <multi_selector id="main_objects"
- label="Main objects"
- icon="icons/Features/cut_shape.png"
- tooltip="Select solid objects"
- type_choice="objects"
- concealment="true">
- <validator id="FeaturesPlugin_ValidatorTransform"/>
- </multi_selector>
- <shape_selector id="axis_object"
- icon="icons/Features/axis.png"
- label="Axis"
- tooltip="Select an edge for axis"
- shape_types="edge"
- default="">
- <validator id="GeomValidators_ShapeType" parameters="line"/>
- </shape_selector>
- <doublevalue
- id="distance"
- label="Distance"
- step="1.0"
- default="0"
- icon="icons/Features/dimension_v.png"
- tooltip="Distance">
- </doublevalue>
+ <toolbox id="CreationMethod">
+ <box id="ByAxisAndDistance"
+ title="By an axis and a distance"
+ icon="icons/Features/translation_vector_32x32.png">
+ <multi_selector id="main_objects"
+ label="Main objects"
+ icon=""
+ tooltip="Select solid objects"
+ type_choice="objects"
+ concealment="true">
+ <validator id="FeaturesPlugin_ValidatorTransform"/>
+ </multi_selector>
+ <shape_selector id="axis_object"
+ icon="icons/Features/axis.png"
+ label="Axis"
+ tooltip="Select an edge for axis"
+ shape_types="edge"
+ default="">
+ <validator id="GeomValidators_ShapeType" parameters="line"/>
+ </shape_selector>
+ <doublevalue id="distance"
+ label="Distance"
+ step="1.0"
+ default="0"
+ icon="icons/Features/dimension_v.png"
+ tooltip="Distance">
+ </doublevalue>
+ </box>
+ <box id="ByDimensions"
+ title="By dimensions in X, in X and in Z"
+ icon="icons/Features/translation_dxyz_32x32.png">
+ <multi_selector id="main_objects"
+ label="Main objects"
+ icon=""
+ tooltip="Select solid objects"
+ type_choice="objects"
+ concealment="true">
+ <validator id="FeaturesPlugin_ValidatorTransform"/>
+ </multi_selector>
+ <doublevalue id="dx"
+ label="DX"
+ step="1.0"
+ default="10"
+ icon=""
+ tooltip="Dimension in X">
+ </doublevalue>
+ <doublevalue id="dy"
+ label="DY"
+ step="1.0"
+ default="0"
+ icon=""
+ tooltip="Dimension in Y">
+ </doublevalue>
+ <doublevalue id="dz"
+ label="DZ"
+ step="1.0"
+ default="0"
+ icon=""
+ tooltip="Dimension in Z">
+ </doublevalue>
+ </box>
+ </toolbox>
</source>
\ No newline at end of file
-// 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<GeomAPI_Trsf.h>
MY_TRSF->SetTranslation(gp_Vec(theAxis->impl<gp_Ax1>().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<GeomAPI_Ax1> theAxis,
const double theAngle)
-// 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_
*/
GEOMAPI_EXPORT void setTranslation(const std::shared_ptr<GeomAPI_Ax1> 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.
#include "GeomAlgoAPI_ShapeAPI.h"
#include <GeomAlgoAPI_Box.h>
+#include <GeomAlgoAPI_Translation.h>
#include <GeomAPI_Pnt.h>
#include <GeomAPI_Edge.h>
}
return aBoxAlgo.shape();
}
+
+ //=========================================================================================================
+ std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
+ std::shared_ptr<GeomAPI_Shape> theSourceShape,
+ std::shared_ptr<GeomAPI_Ax1> 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<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
+ std::shared_ptr<GeomAPI_Shape> 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();
+ }
}
#ifndef GEOMALGOAPI_SHAPEAPI_H
#define GEOMALGOAPI_SHAPEAPI_H
-#include <GeomAPI_Shape.h>
-#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Ax1.h>
#include <GeomAPI_Edge.h>
+#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Shape.h>
#include <GeomAlgoAPI_Exception.h>
/// \return a shape
static std::shared_ptr<GeomAPI_Shape> makeBox(std::shared_ptr<GeomAPI_Pnt> theFirstPoint,
std::shared_ptr<GeomAPI_Pnt> 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<GeomAPI_Shape> makeTranslation(
+ std::shared_ptr<GeomAPI_Shape> theSourceShape,
+ std::shared_ptr<GeomAPI_Ax1> 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<GeomAPI_Shape> makeTranslation(
+ std::shared_ptr<GeomAPI_Shape> theSourceShape,
+ const double theDx,
+ const double theDy,
+ const double theDz) throw (GeomAlgoAPI_Exception);
};
}
#endif
// File: GeomAlgoAPI_Translation.cpp
// Created: 8 June 2015
// Author: Dmitry Bobylev
+//
+// Modified by Clarisse Genrault (CEA) : 17 Nov 2016
#include "GeomAlgoAPI_Translation.h"
#include <BRepBuilderAPI_Transform.hxx>
+#include <Precision.hxx>
#include <gp_Ax1.hxx>
//=================================================================================================
std::shared_ptr<GeomAPI_Ax1> theAxis,
double theDistance)
{
- build(theSourceShape, theAxis, theDistance);
+ myMethodType = BY_DISTANCE;
+ mySourceShape = theSourceShape;
+ myAxis = theAxis;
+ myDistance = theDistance;
}
//=================================================================================================
-void GeomAlgoAPI_Translation::build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
- std::shared_ptr<GeomAPI_Ax1> theAxis,
- double theDistance)
+GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> 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<gp_Ax1>();
+ 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<TopoDS_Shape>();
- const gp_Ax1& anAxis = theAxis->impl<gp_Ax1>();
+ const TopoDS_Shape& aSourceShape = mySourceShape->impl<TopoDS_Shape>();
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<GeomAPI_Shape> 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
// 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_
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.
GEOMALGOAPI_EXPORT GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
std::shared_ptr<GeomAPI_Ax1> 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<GeomAPI_Shape> 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<GeomAPI_Shape> theSourceShape,
- std::shared_ptr<GeomAPI_Ax1> theAxis,
- double theDistance);
+ MethodType myMethodType; /// Type of method used.
+ std::shared_ptr<GeomAPI_Shape> mySourceShape; /// Shape to be moved.
+ std::shared_ptr<GeomAPI_Ax1> 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