{
FeaturePtr aBase = feature();
const std::string& aDocName = theDumper.name(aBase->document());
-
+
AttributeSelectionListPtr anAttrObjects =
aBase->selectionList(FeaturesPlugin_Translation::OBJECTS_LIST_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());
ModelAPI_AttributeSelection, /** Axis object */,
distance, FeaturesPlugin_Translation::DISTANCE_ID(),
ModelAPI_AttributeDouble, /** Distance */,
- dx, FeaturesPlugin_Translation::DX_ID(),
+ dx, FeaturesPlugin_Translation::DX_ID(),
ModelAPI_AttributeDouble, /** Dimension in X */,
- dy, FeaturesPlugin_Translation::DY_ID(),
+ dy, FeaturesPlugin_Translation::DY_ID(),
ModelAPI_AttributeDouble, /** Dimension in Y */,
- dz, FeaturesPlugin_Translation::DZ_ID(),
+ dz, FeaturesPlugin_Translation::DZ_ID(),
ModelAPI_AttributeDouble, /** Dimension in Z */
)
FEATURESAPI_EXPORT
void setAxisAndDistance(const ModelHighAPI_Selection& theAxisObject,
const ModelHighAPI_Double& theDistance);
-
+
/// Modify CreationMethod, dx, dy, dz attributes of the feature.
FEATURESAPI_EXPORT
void setDimensions(const ModelHighAPI_Double& theDx,
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(),
+
+ data()->addAttribute(FeaturesPlugin_Translation::DX_ID(),
ModelAPI_AttributeDouble::typeId());
- data()->addAttribute(FeaturesPlugin_Translation::DY_ID(),
+ data()->addAttribute(FeaturesPlugin_Translation::DY_ID(),
ModelAPI_AttributeDouble::typeId());
- data()->addAttribute(FeaturesPlugin_Translation::DZ_ID(),
+ data()->addAttribute(FeaturesPlugin_Translation::DZ_ID(),
ModelAPI_AttributeDouble::typeId());
}
{
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();
}
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());
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()));
}
// 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.
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();
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.
std::string aTranslatedName = "Translated";
std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = theTranslationAlgo.mapOfSubShapes();
- FeaturesPlugin_Tools::storeModifiedShapes(theTranslationAlgo, theResultBody,
+ FeaturesPlugin_Tools::storeModifiedShapes(theTranslationAlgo, theResultBody,
theBaseShape, aTranslatedTag, aTranslatedName,
*aSubShapes.get());
}
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()
{
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);
*/
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
}
return aBoxAlgo.shape();
}
-
+
//=========================================================================================================
std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
std::shared_ptr<GeomAPI_Shape> theSourceShape,
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());
}
}
return aTranslationAlgo.shape();
}
-
+
//=========================================================================================================
std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
std::shared_ptr<GeomAPI_Shape> theSourceShape,
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());
}
/// \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.
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.
return true;
}
case BY_DIM: {
- if ((fabs(myDx) < Precision::Confusion()) &&
- (fabs(myDy) < Precision::Confusion()) &&
+ if ((fabs(myDx) < Precision::Confusion()) &&
+ (fabs(myDy) < Precision::Confusion()) &&
(fabs(myDz) < Precision::Confusion())) {
myError = "Translation builder :: Dx, Dy and Dz are null.";
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>();
myError = "Translation builder :: source shape does not contain any actual shape.";
return;
}
-
+
// Transform the shape while copying it.
BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true);
if(!aBuilder) {
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
+
+ /// \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.
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();
theDumper << aBase << " = model.addBox(" << aDocName;
std::string aCreationMethod = aBase->string(PrimitivesPlugin_Box::CREATION_METHOD())->value();
-
+
if(aCreationMethod == PrimitivesPlugin_Box::CREATION_METHOD_BY_DIMENSIONS()) {
AttributeDoublePtr anAttrDx = aBase->real(PrimitivesPlugin_Box::DX_ID());
AttributeDoublePtr anAttrDy = aBase->real(PrimitivesPlugin_Box::DY_ID());
AttributeDoublePtr anAttrDz = aBase->real(PrimitivesPlugin_Box::DZ_ID());
-
theDumper << ", " << anAttrDx << ", " << anAttrDy << ", " << anAttrDz;
} else if (aCreationMethod == PrimitivesPlugin_Box::CREATION_METHOD_BY_TWO_POINTS()) {
AttributeSelectionPtr anAttrFirstPnt =
aBase->selection(PrimitivesPlugin_Box::POINT_FIRST_ID());
AttributeSelectionPtr anAttrSecondPnt =
aBase->selection(PrimitivesPlugin_Box::POINT_SECOND_ID());
-
theDumper << ", " << anAttrFirstPnt << ", " << anAttrSecondPnt;
}