}
}
-//==================================================================================================
-FeaturesAPI_Translation::FeaturesAPI_Translation(
- const std::shared_ptr<ModelAPI_Feature>& theFeature,
- const std::list<ModelHighAPI_Selection>& theMainObjects,
- const ModelHighAPI_Selection& theStartPoint,
- const ModelHighAPI_Selection& theEndPoint)
-: ModelHighAPI_Interface(theFeature)
-{
- if(initialize()) {
- fillAttribute(theMainObjects, mymainObjects);
- setPoints(theStartPoint, theEndPoint);
- }
-}
-
//==================================================================================================
FeaturesAPI_Translation::~FeaturesAPI_Translation()
{
execute();
}
-//==================================================================================================
-void FeaturesAPI_Translation::setPoints(const ModelHighAPI_Selection& theStartPoint,
- const ModelHighAPI_Selection& theEndPoint)
-{
- fillAttribute(FeaturesPlugin_Translation::CREATION_METHOD_BY_TWO_POINTS(), mycreationMethod);
- fillAttribute(theStartPoint, mystartPoint);
- fillAttribute(theEndPoint, myendPoint);
-
- execute();
-}
-
//==================================================================================================
void FeaturesAPI_Translation::dump(ModelHighAPI_Dumper& theDumper) const
{
AttributeDoublePtr anAttrDy = aBase->real(FeaturesPlugin_Translation::DY_ID());
AttributeDoublePtr anAttrDz = aBase->real(FeaturesPlugin_Translation::DZ_ID());
theDumper << ", " << anAttrDx << ", " << anAttrDy << ", " << anAttrDz;
- } else if (aCreationMethod == FeaturesPlugin_Translation::CREATION_METHOD_BY_TWO_POINTS()) {
- AttributeSelectionPtr anAttrStartPoint =
- aBase->selection(FeaturesPlugin_Translation::START_POINT_ID());
- AttributeSelectionPtr anAttrEndPoint =
- aBase->selection(FeaturesPlugin_Translation::END_POINT_ID());
- theDumper << ", " << anAttrStartPoint << ", " << anAttrEndPoint;
}
theDumper << ")" << std::endl;
std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Translation::ID());
return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects, theDx, theDy, theDz));
}
-
-//==================================================================================================
-TranslationPtr addTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
- const std::list<ModelHighAPI_Selection>& theMainObjects,
- const ModelHighAPI_Selection& theStartPoint,
- const ModelHighAPI_Selection& theEndPoint)
-{
- std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Translation::ID());
- return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects,
- theStartPoint, theEndPoint));
-}
FEATURESAPI_EXPORT
explicit 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);
-
- /// Constructor with values.
- FEATURESAPI_EXPORT
- explicit FeaturesAPI_Translation(const std::shared_ptr<ModelAPI_Feature>& theFeature,
- const std::list<ModelHighAPI_Selection>& theMainObjects,
- const ModelHighAPI_Selection& theStartPoint,
- const ModelHighAPI_Selection& theEndPoint);
+ const ModelHighAPI_Double& theDx,
+ const ModelHighAPI_Double& theDy,
+ const ModelHighAPI_Double& theDz);
/// Destructor.
FEATURESAPI_EXPORT
virtual ~FeaturesAPI_Translation();
- INTERFACE_9(FeaturesPlugin_Translation::ID(),
+ INTERFACE_7(FeaturesPlugin_Translation::ID(),
creationMethod, FeaturesPlugin_Translation::CREATION_METHOD(),
ModelAPI_AttributeString, /** Creation method */,
mainObjects, FeaturesPlugin_Translation::OBJECTS_LIST_ID(),
dy, FeaturesPlugin_Translation::DY_ID(),
ModelAPI_AttributeDouble, /** Dimension in Y */,
dz, FeaturesPlugin_Translation::DZ_ID(),
- ModelAPI_AttributeDouble, /** Dimension in Z */,
- startPoint, FeaturesPlugin_Translation::START_POINT_ID(),
- ModelAPI_AttributeSelection, /** Start point object */,
- endPoint, FeaturesPlugin_Translation::END_POINT_ID(),
- ModelAPI_AttributeSelection, /** End point object */
+ ModelAPI_AttributeDouble, /** Dimension in Z */
)
/// Set main objects.
const ModelHighAPI_Double& theDy,
const ModelHighAPI_Double& theDz);
- /// Modify CreationMethod, start_point, end_point attributes of the feature.
- FEATURESAPI_EXPORT
- void setPoints(const ModelHighAPI_Selection& theStartPoint,
- const ModelHighAPI_Selection& theEndPoint);
-
/// Dump wrapped feature
FEATURESAPI_EXPORT
virtual void dump(ModelHighAPI_Dumper& theDumper) const;
const ModelHighAPI_Double& theDy,
const ModelHighAPI_Double& theDz);
-/// \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_Selection& theStartPoint,
- const ModelHighAPI_Selection& theEndPoint);
-
#endif // FeaturesAPI_Translation_H_
aSession.startOperation()
aTranslation2 = model.addTranslation(aDocument, [model.selection("SOLID", "Box_1_1")], 10, 10, 10).result()
aSession.finishOperation()
-assert (aTranslation2 is not None)
-
-# Perform a translation by two points
-aSession.startOperation()
-aPoint1 = model.addPoint(aDocument, 0, 0, 0).result()
-aPoint2 = model.addPoint(aDocument, 10, 10, 0).result()
-aTranslation3 = model.addTranslation(aDocument, [model.selection("SOLID", "Box_1_1")], aPoint1, aPoint2).result()
-aSession.finishOperation()
assert (aTranslation2 is not None)
\ No newline at end of file
#include <GeomAPI_Edge.h>
#include <GeomAPI_Lin.h>
-#include <GeomAlgoAPI_PointBuilder.h>
-
#include <FeaturesPlugin_Tools.h>
//=================================================================================================
ModelAPI_AttributeDouble::typeId());
data()->addAttribute(FeaturesPlugin_Translation::DZ_ID(),
ModelAPI_AttributeDouble::typeId());
-
- data()->addAttribute(FeaturesPlugin_Translation::START_POINT_ID(),
- ModelAPI_AttributeSelection::typeId());
- data()->addAttribute(FeaturesPlugin_Translation::END_POINT_ID(),
- ModelAPI_AttributeSelection::typeId());
}
//=================================================================================================
if (aMethodType == CREATION_METHOD_BY_DIMENSIONS()) {
performTranslationByDimensions();
}
-
- if (aMethodType == CREATION_METHOD_BY_TWO_POINTS()) {
- performTranslationByTwoPoints();
- }
}
//=================================================================================================
removeResults(aResultIndex);
}
-//=================================================================================================
-void FeaturesPlugin_Translation::performTranslationByTwoPoints()
-{
- // 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 the start point and the end point
- AttributeSelectionPtr aRef1 = data()->selection(FeaturesPlugin_Translation::START_POINT_ID());
- AttributeSelectionPtr aRef2 = data()->selection(FeaturesPlugin_Translation::END_POINT_ID());
- std::shared_ptr<GeomAPI_Pnt> aFirstPoint;
- std::shared_ptr<GeomAPI_Pnt> aSecondPoint;
- if ((aRef1.get() != NULL) && (aRef2.get() != NULL)) {
- GeomShapePtr aShape1 = aRef1->value();
- if (!aShape1.get()) //If we can't get the points directly, try getting them from the context
- aShape1 = aRef1->context()->shape();
- GeomShapePtr aShape2 = aRef2->value();
- if (!aShape2.get())
- aShape2 = aRef2->context()->shape();
- if (aShape1 && aShape2) {
- aFirstPoint = GeomAlgoAPI_PointBuilder::point(aShape1);
- aSecondPoint = GeomAlgoAPI_PointBuilder::point(aShape2);
- }
- }
-
- // 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(aFirstPoint, aSecondPoint);
- 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, aFirstPoint, aSecondPoint);
-
- 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::loadNamingDS(GeomAlgoAPI_Translation& theTranslationAlgo,
std::shared_ptr<ModelAPI_ResultBody> theResultBody,
return MY_CREATION_METHOD_ID;
}
- /// Attribute name for creation method "ByTwoPoints".
- inline static const std::string& CREATION_METHOD_BY_TWO_POINTS()
- {
- static const std::string MY_CREATION_METHOD_ID("ByTwoPoints");
- return MY_CREATION_METHOD_ID;
- }
-
/// Attribute name of referenced objects.
inline static const std::string& OBJECTS_LIST_ID()
{
return MY_DZ_ID;
}
- /// Attribute name of start point.
- inline static const std::string& START_POINT_ID()
- {
- static const std::string MY_START_POINT_ID("start_point");
- return MY_START_POINT_ID;
- }
-
- /// Attribute name of end point.
- inline static const std::string& END_POINT_ID()
- {
- static const std::string MY_END_POINT_ID("end_point");
- return MY_END_POINT_ID;
- }
-
/// \return the kind of a feature.
FEATURESPLUGIN_EXPORT virtual const std::string& getKind()
{
///Perform the translation using three dimensions X, Y and Z
void performTranslationByDimensions();
- ///Perform the translation usind two points
- void performTranslationByTwoPoints();
-
void loadNamingDS(GeomAlgoAPI_Translation& theTranslationAlgo,
std::shared_ptr<ModelAPI_ResultBody> theResultBody,
std::shared_ptr<GeomAPI_Shape> theBaseShape);
shape_types="vertices edges wires faces shells solids compsolids compounds">
<validator id="FeaturesPlugin_ValidatorCompositeLauncher" parameters="base,Sketch"/>
</sketch_launcher>
+ <multi_selector id="base"
+ label="Base objects:"
+ tooltip="Select a base objects"
+ type_choice="vertices edges wires faces shells compounds"
+ concealment="true">
+ <validator id="FeaturesPlugin_ValidatorBaseForGeneration" parameters="vertex,edge,wire,face,shell,compound"/>
+ </multi_selector>
+ <shape_selector id="direction_object"
+ icon="icons/Features/axis.png"
+ label="Direction"
+ tooltip="Select an edge for direction"
+ shape_types="edge"
+ default="<base normal>">
+ <validator id="GeomValidators_ShapeType" parameters="empty,line"/>
+ </shape_selector>
<toolbox id="CreationMethod">
<box id="BySizes"
title="By sizes"
</groupbox>
</box>
</toolbox>
- <multi_selector id="base"
- label="Base objects:"
- tooltip="Select a base objects"
- type_choice="vertices edges wires faces shells compounds"
- concealment="true">
- <validator id="FeaturesPlugin_ValidatorBaseForGeneration" parameters="vertex,edge,wire,face,shell,compound"/>
- </multi_selector>
- <shape_selector id="direction_object"
- icon="icons/Features/axis.png"
- label="Direction"
- tooltip="Select an edge for direction"
- shape_types="edge"
- default="<base normal>">
- <validator id="GeomValidators_ShapeType" parameters="empty,line"/>
- </shape_selector>
<validator id="GeomValidators_ZeroOffset" parameters="CreationMethod,BySizes,base,to_size,from_size,to_object,to_offset,from_object,from_offset"/>
<validator id="FeaturesPlugin_ValidatorExtrusionDir" parameters="base,direction_object"/>
</source>
tooltip="Dimension in Z">
</doublevalue>
</box>
- <box id="ByTwoPoints"
- title="By two points"
- icon="icons/Features/translation_2pt_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="start_point"
- icon=""
- label="Start point"
- tooltip="Select the start point to define the axis"
- shape_types="vertex"
- default="">
- <validator id="GeomValidators_ShapeType" parameters="vertex"/>
- <validator id="GeomValidators_ConstructionComposite"/>
- </shape_selector>
- <shape_selector id="end_point"
- icon=""
- label="End point"
- tooltip="Select the end point to define the axis"
- shape_types="vertex"
- default="">
- <validator id="GeomValidators_ShapeType" parameters="vertex"/>
- <validator id="GeomValidators_ConstructionComposite"/>
- <validator id="GeomValidators_DifferentShapes"/>
- </shape_selector>
- </box>
</toolbox>
</source>
\ No newline at end of file
MY_TRSF->SetTranslation(gp_Vec(theDx, theDy, theDz));
}
-//=================================================================================================
-void GeomAPI_Trsf::setTranslation(const std::shared_ptr<GeomAPI_Pnt> theStartPoint,
- const std::shared_ptr<GeomAPI_Pnt> theEndPoint)
-{
- MY_TRSF->SetTranslation(theStartPoint->impl<gp_Pnt>(), theEndPoint->impl<gp_Pnt>());
-}
-
//=================================================================================================
void GeomAPI_Trsf::setRotation(const std::shared_ptr<GeomAPI_Ax1> theAxis,
const double theAngle)
#include <memory>
class GeomAPI_Ax1;
-class GeomAPI_Pnt;
/**\class GeomAPI_Trsf
* \ingroup DataModel
const double theDy,
const double theDz);
- /** \brief Sets a translation transformation using two points.
- * \param[in] theStartPoint Start point of the translation vector.
- * \param[in] theEndPoint End point of the translation vector.
- */
- GEOMAPI_EXPORT void setTranslation(const std::shared_ptr<GeomAPI_Pnt> theStartPoint,
- const std::shared_ptr<GeomAPI_Pnt> theEndPoint);
-
/** \brief Sets a rotation transformation.
* \param[in] theAxis rotation axis.
* \param[in] theAngle rotation angle(in degree).
}
return aTranslationAlgo.shape();
}
-
- //=========================================================================================================
- std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
- std::shared_ptr<GeomAPI_Shape> theSourceShape,
- std::shared_ptr<GeomAPI_Pnt> theStartPoint,
- std::shared_ptr<GeomAPI_Pnt> theEndPoint) throw (GeomAlgoAPI_Exception)
- {
- GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theStartPoint, theEndPoint);
-
- if (!aTranslationAlgo.check()) {
- throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
- }
-
- aTranslationAlgo.build();
-
- if(!aTranslationAlgo.isDone()) {
- throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
- }
- if (!aTranslationAlgo.checkValid("Translation builder with two points")) {
- throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
- }
- return aTranslationAlgo.shape();
- }
}
const double theDx,
const double theDy,
const double theDz) throw (GeomAlgoAPI_Exception);
-
- /// Performs a translation from two points.
- /// \param theSourceShape Shape to be moved.
- /// \param theStartPoint Movement start point.
- /// \param theEndPoint Movement end point.
- /// \return a shape
- static std::shared_ptr<GeomAPI_Shape> makeTranslation(
- std::shared_ptr<GeomAPI_Shape> theSourceShape,
- std::shared_ptr<GeomAPI_Pnt> theStartPoint,
- std::shared_ptr<GeomAPI_Pnt> theEndPoint) throw (GeomAlgoAPI_Exception);
};
}
#endif
myDz = theDz;
}
-//=================================================================================================
-GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
- std::shared_ptr<GeomAPI_Pnt> theStartPoint,
- std::shared_ptr<GeomAPI_Pnt> theEndPoint)
-{
- myMethodType = BY_POINTS;
- mySourceShape = theSourceShape;
- myStartPoint = theStartPoint;
- myEndPoint = theEndPoint;
-}
-
//=================================================================================================
bool GeomAlgoAPI_Translation::check()
{
}
return true;
}
- case BY_POINTS: {
- if (!myStartPoint) {
- myError = "Translation builder :: start point is invalid.";
- return false;
- }
- if (!myEndPoint) {
- myError = "Translation builder :: start point is invalid.";
- return false;
- }
- if (!mySourceShape) {
- myError = "Translation builder :: source shape is invalid.";
- return false;
- }
- return true;
- }
default: {
myError = "Translation builder :: method not implemented.";
return false;
aTrsf->SetTranslation(gp_Vec(myDx, myDy, myDz));
break;
}
- case BY_POINTS: {
- const gp_Pnt& aStartPoint = myStartPoint->impl<gp_Pnt>();
- const gp_Pnt& aEndPoint = myEndPoint->impl<gp_Pnt>();
- aTrsf->SetTranslation(aStartPoint, aEndPoint);
- break;
- }
default: {
myError = "Translation builder :: method not supported";
return;
double theDy,
double theDz);
- /// \brief Creates an object which is obtained from current object by moving it along a vector
- /// defined by two points.
- /// \param[in] theSourceShape the shape to be moved.
- /// \param[in] theStartPoint the movement start point.
- /// \param[in] theEndPoint the movement end point.
- GEOMALGOAPI_EXPORT GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
- std::shared_ptr<GeomAPI_Pnt> theStartPoint,
- std::shared_ptr<GeomAPI_Pnt> theEndPoint);
-
/// Checks if data for the translation execution is OK.
GEOMALGOAPI_EXPORT bool check();
double myDx; /// Movement dimension on X.
double myDy; /// Movement dimension on Y.
double myDz; /// Movement dimension on Z.
- std::shared_ptr<GeomAPI_Pnt> myStartPoint; /// Movement start point.
- std::shared_ptr<GeomAPI_Pnt> myEndPoint; /// Movement end point.
};
#endif
except myExcept, ec:
print ec.what()
-
-# Perfom a translation with two points.
-try :
- pnt1 = pnt(10.,0.,0.)
- pnt2 = pnt(10.,15.,0.)
- translation3 = shaperpy.makeTranslation(box,pnt1,pnt2)
-
-except myExcept, ec:
- print ec.what()