From: dbv Date: Tue, 8 Sep 2015 13:05:54 +0000 (+0300) Subject: Code clean up X-Git-Tag: V_1.4.0_beta4~76 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=fbfcc4fd956a374c8d380c2da280c61eaa57bcfd;p=modules%2Fshaper.git Code clean up --- diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index c475ee87d..b7cbad1ba 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -9,7 +9,7 @@ SET(PROJECT_HEADERS FeaturesPlugin_Extrusion.h FeaturesPlugin_Revolution.h FeaturesPlugin_Rotation.h - FeaturesPlugin_Movement.h + FeaturesPlugin_Translation.h FeaturesPlugin_Boolean.h FeaturesPlugin_Group.h FeaturesPlugin_Partition.h @@ -28,7 +28,7 @@ SET(PROJECT_SOURCES FeaturesPlugin_Extrusion.cpp FeaturesPlugin_Revolution.cpp FeaturesPlugin_Rotation.cpp - FeaturesPlugin_Movement.cpp + FeaturesPlugin_Translation.cpp FeaturesPlugin_Boolean.cpp FeaturesPlugin_Group.cpp FeaturesPlugin_Partition.cpp @@ -86,7 +86,7 @@ ADD_UNIT_TESTS(TestExtrusion.py TestRevolutionCut.py TestRevolutionFuse.py TestPartition.py - TestMovement.py + TestTranslation.py TestRotation.py TestBoolean.py TestMultiBoolean.py diff --git a/src/FeaturesPlugin/FeaturesPlugin_Movement.cpp b/src/FeaturesPlugin/FeaturesPlugin_Movement.cpp deleted file mode 100644 index ebe2eb808..000000000 --- a/src/FeaturesPlugin/FeaturesPlugin_Movement.cpp +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: FeaturesPlugin_Movement.cpp -// Created: 8 June 2015 -// Author: Dmitry Bobylev - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -//================================================================================================= -FeaturesPlugin_Movement::FeaturesPlugin_Movement() -{ -} - -//================================================================================================= -void FeaturesPlugin_Movement::initAttributes() -{ - AttributeSelectionListPtr aSelection = - std::dynamic_pointer_cast(data()->addAttribute( - FeaturesPlugin_Movement::OBJECTS_LIST_ID(), ModelAPI_AttributeSelectionList::typeId())); - // revolution works with faces always - aSelection->setSelectionType("SOLID"); - - data()->addAttribute(FeaturesPlugin_Movement::AXIS_OBJECT_ID(), ModelAPI_AttributeSelection::typeId()); - data()->addAttribute(FeaturesPlugin_Movement::DISTANCE_ID(), ModelAPI_AttributeDouble::typeId()); -} - -//================================================================================================= -void FeaturesPlugin_Movement::execute() -{ - // Getting objects. - ListOfShape anObjects; - std::list aContextes; - AttributeSelectionListPtr anObjectsSelList = selectionList(FeaturesPlugin_Movement::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()) { - return; - } - 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_Movement::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() && - 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())); - } - - // Getting distance. - double aDistance = real(FeaturesPlugin_Movement::DISTANCE_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(); - GeomAlgoAPI_Movement aMovementAlgo(aBaseShape, anAxis, aDistance, isPart); - - // Checking that the algorithm worked properly. - if(!aMovementAlgo.isDone()) { - static const std::string aFeatureError = "Movement algorithm failed"; - setError(aFeatureError); - break; - } - if(aMovementAlgo.shape()->isNull()) { - static const std::string aShapeError = "Resulting shape is Null"; - setError(aShapeError); - break; - } - if(!aMovementAlgo.isValid()) { - std::string aFeatureError = "Warning: resulting shape is not valid"; - setError(aFeatureError); - break; - } - - // Setting result. - if (isPart) { - ResultPartPtr anOrigin = std::dynamic_pointer_cast(*aContext); - ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex); - aResultPart->setTrsf(*aContext, aMovementAlgo.transformation()); - setResult(aResultPart); - } else { - ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); - LoadNamingDS(aMovementAlgo, aResultBody, aBaseShape); - setResult(aResultBody, aResultIndex); - } - aResultIndex++; - } - - // Remove the rest results if there were produced in the previous pass. - removeResults(aResultIndex); -} - -void FeaturesPlugin_Movement::LoadNamingDS(const GeomAlgoAPI_Movement& theMovementAlgo, - std::shared_ptr theResultBody, - std::shared_ptr theBaseShape) -{ - // Store result. - theResultBody->storeModified(theBaseShape, theMovementAlgo.shape()); - - std::shared_ptr aSubShapes = theMovementAlgo.mapOfShapes(); - - int aMovedTag = 1; - std::string aMovedName = "Moved"; - theResultBody->loadAndOrientModifiedShapes(theMovementAlgo.makeShape().get(), - theBaseShape, GeomAPI_Shape::FACE, - aMovedTag, aMovedName, *aSubShapes.get()); - -} diff --git a/src/FeaturesPlugin/FeaturesPlugin_Movement.h b/src/FeaturesPlugin/FeaturesPlugin_Movement.h deleted file mode 100644 index 27e4becfb..000000000 --- a/src/FeaturesPlugin/FeaturesPlugin_Movement.h +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: FeaturesPlugin_Movement.h -// Created: 8 June 2015 -// Author: Dmitry Bobylev - -#ifndef FeaturesPlugin_Movement_H_ -#define FeaturesPlugin_Movement_H_ - -#include - -#include - -#include - -/** \class FeaturesPlugin_Movement - * \ingroup Plugins - * \brief Feature for movement objects along the axis. - */ -class FeaturesPlugin_Movement : public ModelAPI_Feature -{ - public: - /// Movement kind. - inline static const std::string& ID() - { - static const std::string MY_MOVEMENT_ID("Translation"); - return MY_MOVEMENT_ID; - } - - /// Attribute name of referenced objects. - inline static const std::string& OBJECTS_LIST_ID() - { - static const std::string MY_OBJECTS_LIST_ID("main_objects"); - return MY_OBJECTS_LIST_ID; - } - - /// Attribute name of an axis. - inline static const std::string& AXIS_OBJECT_ID() - { - static const std::string MY_AXIS_OBJECT_ID("axis_object"); - return MY_AXIS_OBJECT_ID; - } - - /// Attribute name of distance. - inline static const std::string& DISTANCE_ID() - { - static const std::string MY_DISTANCE_ID("distance"); - return MY_DISTANCE_ID; - } - - /// \return the kind of a feature. - FEATURESPLUGIN_EXPORT virtual const std::string& getKind() - { - static std::string MY_KIND = FeaturesPlugin_Movement::ID(); - return MY_KIND; - } - - /// Creates a new part document if needed. - FEATURESPLUGIN_EXPORT virtual void execute(); - - /// Request for initialization of data model of the feature: adding all attributes. - FEATURESPLUGIN_EXPORT virtual void initAttributes(); - - /// Use plugin manager for features creation. - FeaturesPlugin_Movement(); - -private: - void LoadNamingDS(const GeomAlgoAPI_Movement& theMovementAlgo, - std::shared_ptr theResultBody, - std::shared_ptr theBaseShape); -}; - -#endif diff --git a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp index d3d243a4a..c8ab834cc 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include @@ -40,8 +40,8 @@ FeaturePtr FeaturesPlugin_Plugin::createFeature(string theFeatureID) return FeaturePtr(new FeaturesPlugin_Revolution); } else if (theFeatureID == FeaturesPlugin_Rotation::ID()) { return FeaturePtr(new FeaturesPlugin_Rotation); - } else if (theFeatureID == FeaturesPlugin_Movement::ID()) { - return FeaturePtr(new FeaturesPlugin_Movement); + } else if (theFeatureID == FeaturesPlugin_Translation::ID()) { + return FeaturePtr(new FeaturesPlugin_Translation); } else if (theFeatureID == FeaturesPlugin_Boolean::ID()) { return FeaturePtr(new FeaturesPlugin_Boolean); } else if (theFeatureID == FeaturesPlugin_Group::ID()) { diff --git a/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp b/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp new file mode 100644 index 000000000..d1ff455a2 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_Translation.cpp @@ -0,0 +1,133 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: FeaturesPlugin_Translation.cpp +// Created: 8 June 2015 +// Author: Dmitry Bobylev + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +//================================================================================================= +FeaturesPlugin_Translation::FeaturesPlugin_Translation() +{ +} + +//================================================================================================= +void FeaturesPlugin_Translation::initAttributes() +{ + AttributeSelectionListPtr aSelection = + std::dynamic_pointer_cast(data()->addAttribute( + FeaturesPlugin_Translation::OBJECTS_LIST_ID(), ModelAPI_AttributeSelectionList::typeId())); + // revolution works with faces always + aSelection->setSelectionType("SOLID"); + + data()->addAttribute(FeaturesPlugin_Translation::AXIS_OBJECT_ID(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(FeaturesPlugin_Translation::DISTANCE_ID(), ModelAPI_AttributeDouble::typeId()); +} + +//================================================================================================= +void FeaturesPlugin_Translation::execute() +{ + // 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()) { + return; + } + 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()); + if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) { + anEdge = std::shared_ptr(new GeomAPI_Edge(anObjRef->value())); + } 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())); + } + + // Getting distance. + double aDistance = real(FeaturesPlugin_Translation::DISTANCE_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(); + GeomAlgoAPI_Translation aMovementAlgo(aBaseShape, anAxis, aDistance, isPart); + + // Checking that the algorithm worked properly. + if(!aMovementAlgo.isDone()) { + static const std::string aFeatureError = "Movement algorithm failed"; + setError(aFeatureError); + break; + } + if(aMovementAlgo.shape()->isNull()) { + static const std::string aShapeError = "Resulting shape is Null"; + setError(aShapeError); + break; + } + if(!aMovementAlgo.isValid()) { + std::string aFeatureError = "Warning: resulting shape is not valid"; + setError(aFeatureError); + break; + } + + // Setting result. + if (isPart) { + ResultPartPtr anOrigin = std::dynamic_pointer_cast(*aContext); + ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex); + aResultPart->setTrsf(*aContext, aMovementAlgo.transformation()); + setResult(aResultPart); + } else { + ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); + LoadNamingDS(aMovementAlgo, aResultBody, aBaseShape); + setResult(aResultBody, aResultIndex); + } + aResultIndex++; + } + + // Remove the rest results if there were produced in the previous pass. + removeResults(aResultIndex); +} + +void FeaturesPlugin_Translation::LoadNamingDS(const GeomAlgoAPI_Translation& theMovementAlgo, + std::shared_ptr theResultBody, + std::shared_ptr theBaseShape) +{ + // Store result. + theResultBody->storeModified(theBaseShape, theMovementAlgo.shape()); + + std::shared_ptr aSubShapes = theMovementAlgo.mapOfShapes(); + + int aMovedTag = 1; + std::string aMovedName = "Moved"; + theResultBody->loadAndOrientModifiedShapes(theMovementAlgo.makeShape().get(), + theBaseShape, GeomAPI_Shape::FACE, + aMovedTag, aMovedName, *aSubShapes.get()); + +} diff --git a/src/FeaturesPlugin/FeaturesPlugin_Translation.h b/src/FeaturesPlugin/FeaturesPlugin_Translation.h new file mode 100644 index 000000000..2f6ce2d92 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_Translation.h @@ -0,0 +1,73 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: FeaturesPlugin_Translation.h +// Created: 8 June 2015 +// Author: Dmitry Bobylev + +#ifndef FeaturesPlugin_Translation_H_ +#define FeaturesPlugin_Translation_H_ + +#include + +#include + +#include + +/** \class FeaturesPlugin_Translation + * \ingroup Plugins + * \brief Feature for movement objects along the axis. + */ +class FeaturesPlugin_Translation : public ModelAPI_Feature +{ + public: + /// Movement kind. + inline static const std::string& ID() + { + static const std::string MY_MOVEMENT_ID("Translation"); + return MY_MOVEMENT_ID; + } + + /// Attribute name of referenced objects. + inline static const std::string& OBJECTS_LIST_ID() + { + static const std::string MY_OBJECTS_LIST_ID("main_objects"); + return MY_OBJECTS_LIST_ID; + } + + /// Attribute name of an axis. + inline static const std::string& AXIS_OBJECT_ID() + { + static const std::string MY_AXIS_OBJECT_ID("axis_object"); + return MY_AXIS_OBJECT_ID; + } + + /// Attribute name of distance. + inline static const std::string& DISTANCE_ID() + { + static const std::string MY_DISTANCE_ID("distance"); + return MY_DISTANCE_ID; + } + + /// \return the kind of a feature. + FEATURESPLUGIN_EXPORT virtual const std::string& getKind() + { + static std::string MY_KIND = FeaturesPlugin_Translation::ID(); + return MY_KIND; + } + + /// Creates a new part document if needed. + FEATURESPLUGIN_EXPORT virtual void execute(); + + /// Request for initialization of data model of the feature: adding all attributes. + FEATURESPLUGIN_EXPORT virtual void initAttributes(); + + /// Use plugin manager for features creation. + FeaturesPlugin_Translation(); + +private: + void LoadNamingDS(const GeomAlgoAPI_Translation& theMovementAlgo, + std::shared_ptr theResultBody, + std::shared_ptr theBaseShape); +}; + +#endif diff --git a/src/FeaturesPlugin/Test/TestMovement.py b/src/FeaturesPlugin/Test/TestMovement.py deleted file mode 100644 index dd90e09ea..000000000 --- a/src/FeaturesPlugin/Test/TestMovement.py +++ /dev/null @@ -1,134 +0,0 @@ -""" - TestMovement.py - Unit test of FeaturesPlugin_Movement class - - class FeaturesPlugin_Movement : public ModelAPI_Feature - static const std::string MY_MOVEMENT_ID("Translation"); - static const std::string MY_OBJECTS_LIST_ID("main_objects"); - static const std::string MY_AXIS_OBJECT_ID("axis_object"); - static const std::string MY_DISTANCE_ID("distance"); - - data()->addAttribute(OBJECTS_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()); - data()->addAttribute(AXIS_OBJECT_ID(), ModelAPI_AttributeSelection::typeId()); - data()->addAttribute(DISTANCE_ID(), ModelAPI_AttributeDouble::typeId()); -""" -#========================================================================= -# Initialization of the test -#========================================================================= -from ModelAPI import * -from GeomDataAPI import * -from GeomAlgoAPI import * -from GeomAPI import * -import math - -aSession = ModelAPI_Session.get() -aDocument = aSession.moduleDocument() -# Create a part for movement -aSession.startOperation() -aPartFeature = aDocument.addFeature("Part") -aSession.finishOperation() -assert (len(aPartFeature.results()) == 1) -# Another way is: -# aPart = aSession.activeDocument() -aPartResult = modelAPI_ResultPart(aPartFeature.firstResult()) -aPart = aPartResult.partDoc() - -#========================================================================= -# Create a sketch circle to extrude -#========================================================================= -aSession.startOperation() -aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch")) -origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin")) -origin.setValue(0, 0, 0) -dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX")) -dirx.setValue(1, 0, 0) -norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm")) -norm.setValue(0, 0, 1) -# Create circle -aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle") -anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter")) -aCircleRadius = aSketchCircle.real("CircleRadius") -anCircleCentr.setValue(50, 50) -aCircleRadius.setValue(20) -aSession.finishOperation() -#========================================================================= -# Make extrusion on circle -#========================================================================= -# Build shape from sketcher results -aCircleSketchResult = aCircleSketchFeature.firstResult() -aCircleSketchEdges = modelAPI_ResultConstruction(aCircleSketchResult).shape() -origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin")).pnt() -dirX = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX")).dir() -norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm")).dir() -aCircleSketchFaces = ShapeList() -GeomAlgoAPI_SketchBuilder.createFaces( - origin, dirX, norm, aCircleSketchEdges, aCircleSketchFaces) -assert (len(aCircleSketchFaces) > 0) -assert (aCircleSketchFaces[0] is not None) -# Create extrusion -aSession.startOperation() -anExtrusionFt = aPart.addFeature("Extrusion") -assert (anExtrusionFt.getKind() == "Extrusion") -# selection type FACE=4 -anExtrusionFt.selectionList("base").append( - aCircleSketchResult, aCircleSketchFaces[0]) -anExtrusionFt.string("CreationMethod").setValue("BySizes") -anExtrusionFt.real("to_size").setValue(50) -anExtrusionFt.real("from_size").setValue(0) -anExtrusionFt.real("to_offset").setValue(0) #TODO: remove -anExtrusionFt.real("from_offset").setValue(0) #TODO: remove -anExtrusionFt.execute() -aSession.finishOperation() -assert (anExtrusionFt.real("to_size").value() == 50) - -# Check extrusion results -assert (len(anExtrusionFt.results()) > 0) -anExtrusionResult = modelAPI_ResultBody(anExtrusionFt.firstResult()) -assert (anExtrusionResult is not None) - -#========================================================================= -# Create a sketch line to movement -#========================================================================= -aSession.startOperation() -aLineSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch")) -origin = geomDataAPI_Point(aLineSketchFeature.attribute("Origin")) -origin.setValue(0, 0, 0) -dirx = geomDataAPI_Dir(aLineSketchFeature.attribute("DirX")) -dirx.setValue(1, 0, 0) -norm = geomDataAPI_Dir(aLineSketchFeature.attribute("Norm")) -norm.setValue(0, 0, 1) - -aSketchLine = aLineSketchFeature.addFeature("SketchLine") -aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint")) -aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint")) -aLineStartPoint.setValue(-100, -100) -aLineEndPoint.setValue(100, -100) -aSession.finishOperation() - -# Build shape from sketcher results -aLineSketchResult = aLineSketchFeature.firstResult() -aLineSketchShape = modelAPI_ResultConstruction(aLineSketchResult).shape() -aShapeExplorer = GeomAPI_ShapeExplorer(aLineSketchShape, GeomAPI_Shape.EDGE) -aLineEdge = aShapeExplorer.current() - -#========================================================================= -# Test movement -#========================================================================= -aSession.startOperation() -aMoveFt = aPart.addFeature("Translation") -assert (aMoveFt.getKind() == "Translation") -aMoveFt.selectionList("main_objects").append( - anExtrusionResult, anExtrusionResult.shape()) -aMoveFt.selection("axis_object").setValue(aLineSketchResult, aLineEdge) -aMoveFt.real("distance").setValue(100) -aMoveFt.execute() -aSession.finishOperation() -assert (aMoveFt.real("distance").value() == 100) - -# Check movement results -aFactory = ModelAPI_Session.get().validators() -assert (aFactory.validate(aMoveFt)) -assert (len(aMoveFt.results()) > 0) -aMoveResult = modelAPI_ResultBody(aMoveFt.firstResult()) -assert (aMoveResult is not None) - diff --git a/src/FeaturesPlugin/Test/TestTranslation.py b/src/FeaturesPlugin/Test/TestTranslation.py new file mode 100644 index 000000000..dd90e09ea --- /dev/null +++ b/src/FeaturesPlugin/Test/TestTranslation.py @@ -0,0 +1,134 @@ +""" + TestMovement.py + Unit test of FeaturesPlugin_Movement class + + class FeaturesPlugin_Movement : public ModelAPI_Feature + static const std::string MY_MOVEMENT_ID("Translation"); + static const std::string MY_OBJECTS_LIST_ID("main_objects"); + static const std::string MY_AXIS_OBJECT_ID("axis_object"); + static const std::string MY_DISTANCE_ID("distance"); + + data()->addAttribute(OBJECTS_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()); + data()->addAttribute(AXIS_OBJECT_ID(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(DISTANCE_ID(), ModelAPI_AttributeDouble::typeId()); +""" +#========================================================================= +# Initialization of the test +#========================================================================= +from ModelAPI import * +from GeomDataAPI import * +from GeomAlgoAPI import * +from GeomAPI import * +import math + +aSession = ModelAPI_Session.get() +aDocument = aSession.moduleDocument() +# Create a part for movement +aSession.startOperation() +aPartFeature = aDocument.addFeature("Part") +aSession.finishOperation() +assert (len(aPartFeature.results()) == 1) +# Another way is: +# aPart = aSession.activeDocument() +aPartResult = modelAPI_ResultPart(aPartFeature.firstResult()) +aPart = aPartResult.partDoc() + +#========================================================================= +# Create a sketch circle to extrude +#========================================================================= +aSession.startOperation() +aCircleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch")) +origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin")) +origin.setValue(0, 0, 0) +dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX")) +dirx.setValue(1, 0, 0) +norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm")) +norm.setValue(0, 0, 1) +# Create circle +aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle") +anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter")) +aCircleRadius = aSketchCircle.real("CircleRadius") +anCircleCentr.setValue(50, 50) +aCircleRadius.setValue(20) +aSession.finishOperation() +#========================================================================= +# Make extrusion on circle +#========================================================================= +# Build shape from sketcher results +aCircleSketchResult = aCircleSketchFeature.firstResult() +aCircleSketchEdges = modelAPI_ResultConstruction(aCircleSketchResult).shape() +origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin")).pnt() +dirX = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX")).dir() +norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm")).dir() +aCircleSketchFaces = ShapeList() +GeomAlgoAPI_SketchBuilder.createFaces( + origin, dirX, norm, aCircleSketchEdges, aCircleSketchFaces) +assert (len(aCircleSketchFaces) > 0) +assert (aCircleSketchFaces[0] is not None) +# Create extrusion +aSession.startOperation() +anExtrusionFt = aPart.addFeature("Extrusion") +assert (anExtrusionFt.getKind() == "Extrusion") +# selection type FACE=4 +anExtrusionFt.selectionList("base").append( + aCircleSketchResult, aCircleSketchFaces[0]) +anExtrusionFt.string("CreationMethod").setValue("BySizes") +anExtrusionFt.real("to_size").setValue(50) +anExtrusionFt.real("from_size").setValue(0) +anExtrusionFt.real("to_offset").setValue(0) #TODO: remove +anExtrusionFt.real("from_offset").setValue(0) #TODO: remove +anExtrusionFt.execute() +aSession.finishOperation() +assert (anExtrusionFt.real("to_size").value() == 50) + +# Check extrusion results +assert (len(anExtrusionFt.results()) > 0) +anExtrusionResult = modelAPI_ResultBody(anExtrusionFt.firstResult()) +assert (anExtrusionResult is not None) + +#========================================================================= +# Create a sketch line to movement +#========================================================================= +aSession.startOperation() +aLineSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch")) +origin = geomDataAPI_Point(aLineSketchFeature.attribute("Origin")) +origin.setValue(0, 0, 0) +dirx = geomDataAPI_Dir(aLineSketchFeature.attribute("DirX")) +dirx.setValue(1, 0, 0) +norm = geomDataAPI_Dir(aLineSketchFeature.attribute("Norm")) +norm.setValue(0, 0, 1) + +aSketchLine = aLineSketchFeature.addFeature("SketchLine") +aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint")) +aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint")) +aLineStartPoint.setValue(-100, -100) +aLineEndPoint.setValue(100, -100) +aSession.finishOperation() + +# Build shape from sketcher results +aLineSketchResult = aLineSketchFeature.firstResult() +aLineSketchShape = modelAPI_ResultConstruction(aLineSketchResult).shape() +aShapeExplorer = GeomAPI_ShapeExplorer(aLineSketchShape, GeomAPI_Shape.EDGE) +aLineEdge = aShapeExplorer.current() + +#========================================================================= +# Test movement +#========================================================================= +aSession.startOperation() +aMoveFt = aPart.addFeature("Translation") +assert (aMoveFt.getKind() == "Translation") +aMoveFt.selectionList("main_objects").append( + anExtrusionResult, anExtrusionResult.shape()) +aMoveFt.selection("axis_object").setValue(aLineSketchResult, aLineEdge) +aMoveFt.real("distance").setValue(100) +aMoveFt.execute() +aSession.finishOperation() +assert (aMoveFt.real("distance").value() == 100) + +# Check movement results +aFactory = ModelAPI_Session.get().validators() +assert (aFactory.validate(aMoveFt)) +assert (len(aMoveFt.results()) > 0) +aMoveResult = modelAPI_ResultBody(aMoveFt.firstResult()) +assert (aMoveResult is not None) + diff --git a/src/GeomAPI/GeomAPI_Ax3.cpp b/src/GeomAPI/GeomAPI_Ax3.cpp index 0ff482b85..7dd2632ce 100644 --- a/src/GeomAPI/GeomAPI_Ax3.cpp +++ b/src/GeomAPI/GeomAPI_Ax3.cpp @@ -67,14 +67,14 @@ std::shared_ptr GeomAPI_Ax3::dirY() const return std::shared_ptr(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z())); } -void GeomAPI_Ax3::setNorm(const std::shared_ptr& theNorm) +void GeomAPI_Ax3::setNormal(const std::shared_ptr& theNorm) { gp_Ax1 aAx1 = MY_AX3->Axis(); aAx1.SetDirection(theNorm->impl()); MY_AX3->SetAxis(aAx1); } -std::shared_ptr GeomAPI_Ax3::norm() const +std::shared_ptr GeomAPI_Ax3::normal() const { gp_Dir aDir = MY_AX3->Axis().Direction(); return std::shared_ptr(new GeomAPI_Dir(aDir.X(),aDir.Y(),aDir.Z())); diff --git a/src/GeomAPI/GeomAPI_Ax3.h b/src/GeomAPI/GeomAPI_Ax3.h index df7ef774d..613513a46 100644 --- a/src/GeomAPI/GeomAPI_Ax3.h +++ b/src/GeomAPI/GeomAPI_Ax3.h @@ -58,11 +58,11 @@ public: /// Sets Z direction vector GEOMAPI_EXPORT - void setNorm(const std::shared_ptr& theNorm); + void setNormal(const std::shared_ptr& theNorm); /// Returns Z direction vector GEOMAPI_EXPORT - std::shared_ptr norm() const; + std::shared_ptr normal() const; /// Converts 2d coordinates from the plane to 3d space point /// \param theX X coordinate diff --git a/src/GeomAPI/GeomAPI_PlanarEdges.cpp b/src/GeomAPI/GeomAPI_PlanarEdges.cpp index 619716256..9bb3fb994 100644 --- a/src/GeomAPI/GeomAPI_PlanarEdges.cpp +++ b/src/GeomAPI/GeomAPI_PlanarEdges.cpp @@ -87,7 +87,7 @@ std::shared_ptr GeomAPI_PlanarEdges::dirY() const std::shared_ptr GeomAPI_PlanarEdges::norm() const { if (hasPlane()) - return myPlane->norm(); + return myPlane->normal(); return std::shared_ptr(); } diff --git a/src/GeomAlgoAPI/CMakeLists.txt b/src/GeomAlgoAPI/CMakeLists.txt index 9c85cf7bd..fb238e478 100644 --- a/src/GeomAlgoAPI/CMakeLists.txt +++ b/src/GeomAlgoAPI/CMakeLists.txt @@ -13,12 +13,11 @@ SET(PROJECT_HEADERS GeomAlgoAPI_EdgeBuilder.h GeomAlgoAPI_PointBuilder.h GeomAlgoAPI_SketchBuilder.h - GeomAlgoAPI_Extrusion.h GeomAlgoAPI_Prism.h GeomAlgoAPI_Revolution.h GeomAlgoAPI_Boolean.h GeomAlgoAPI_Rotation.h - GeomAlgoAPI_Movement.h + GeomAlgoAPI_Translation.h GeomAlgoAPI_MakeShape.h GeomAlgoAPI_MakeShapeCustom.h GeomAlgoAPI_MakeShapeList.h @@ -43,12 +42,11 @@ SET(PROJECT_SOURCES GeomAlgoAPI_EdgeBuilder.cpp GeomAlgoAPI_PointBuilder.cpp GeomAlgoAPI_SketchBuilder.cpp - GeomAlgoAPI_Extrusion.cpp GeomAlgoAPI_Prism.cpp GeomAlgoAPI_Revolution.cpp GeomAlgoAPI_Boolean.cpp GeomAlgoAPI_Rotation.cpp - GeomAlgoAPI_Movement.cpp + GeomAlgoAPI_Translation.cpp GeomAlgoAPI_MakeShape.cpp GeomAlgoAPI_MakeShapeCustom.cpp GeomAlgoAPI_MakeShapeList.cpp diff --git a/src/GeomAlgoAPI/GeomAlgoAPI.i b/src/GeomAlgoAPI/GeomAlgoAPI.i index 1c1c25283..51817d6c1 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI.i +++ b/src/GeomAlgoAPI/GeomAlgoAPI.i @@ -6,12 +6,11 @@ #include "GeomAlgoAPI_CompoundBuilder.h" #include "GeomAlgoAPI_DFLoader.h" #include "GeomAlgoAPI_EdgeBuilder.h" - #include "GeomAlgoAPI_Extrusion.h" #include "GeomAlgoAPI_FaceBuilder.h" #include "GeomAlgoAPI_MakeShape.h" #include "GeomAlgoAPI_MakeShapeCustom.h" #include "GeomAlgoAPI_MakeShapeList.h" - #include "GeomAlgoAPI_Movement.h" + #include "GeomAlgoAPI_Translation.h" #include "GeomAlgoAPI_Placement.h" #include "GeomAlgoAPI_PointBuilder.h" #include "GeomAlgoAPI_Prism.h" @@ -48,12 +47,11 @@ %include "GeomAlgoAPI_CompoundBuilder.h" %include "GeomAlgoAPI_DFLoader.h" %include "GeomAlgoAPI_EdgeBuilder.h" -%include "GeomAlgoAPI_Extrusion.h" %include "GeomAlgoAPI_FaceBuilder.h" %include "GeomAlgoAPI_MakeShape.h" %include "GeomAlgoAPI_MakeShapeCustom.h" %include "GeomAlgoAPI_MakeShapeList.h" -%include "GeomAlgoAPI_Movement.h" +%include "GeomAlgoAPI_Translation.h" %include "GeomAlgoAPI_Placement.h" %include "GeomAlgoAPI_PointBuilder.h" %include "GeomAlgoAPI_Prism.h" diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.cpp deleted file mode 100644 index eecff212a..000000000 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.cpp +++ /dev/null @@ -1,138 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: GeomAlgoAPI_Extrusion.cpp -// Created: 06 Jun 2014 -// Author: Artem ZHIDKOV - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -const double tolerance = Precision::Angular(); -// Constructor -GeomAlgoAPI_Extrusion::GeomAlgoAPI_Extrusion( - std::shared_ptr theBasis, double theSize) -: mySize(theSize), myDone(false), myShape(new GeomAPI_Shape()), - myFirst(new GeomAPI_Shape()), myLast(new GeomAPI_Shape()) -{ - build(theBasis); -} - -//============================================================================ -void GeomAlgoAPI_Extrusion::build(const std::shared_ptr& theBasis) -{ - bool isFirstNorm = true; - gp_Dir aShapeNormal; - TopoDS_Face aBasis = TopoDS::Face(theBasis->impl()); - Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( - BRep_Tool::Surface(aBasis)); - if (aPlane.IsNull()) // non-planar shapes is not supported for extrusion yet - return; - - const gp_Dir& aNormal = aPlane->Pln().Axis().Direction(); - gp_Vec aVec(aNormal); - aVec = aVec * mySize; - - BRepPrimAPI_MakePrism* aBuilder = new BRepPrimAPI_MakePrism(aBasis, aVec); - if(aBuilder) { - setImpl(aBuilder); - myDone = aBuilder->IsDone() == Standard_True; - if (myDone) { - TopoDS_Shape aResult; - if(aBuilder->Shape().ShapeType() == TopAbs_COMPOUND) - aResult = GeomAlgoAPI_DFLoader::refineResult(aBuilder->Shape()); - else - aResult = aBuilder->Shape(); - // fill data map to keep correct orientation of sub-shapes - for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) { - std::shared_ptr aCurrentShape(new GeomAPI_Shape()); - aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current())); - myMap.bind(aCurrentShape, aCurrentShape); - } - myShape->setImpl(new TopoDS_Shape(aResult)); - myFirst->setImpl(new TopoDS_Shape(aBuilder->FirstShape())); - myLast->setImpl(new TopoDS_Shape(aBuilder-> LastShape())); - myMkShape = new GeomAlgoAPI_MakeShape (aBuilder); - } - } -} - -//============================================================================ -const bool GeomAlgoAPI_Extrusion::isDone() const -{return myDone;} - -//============================================================================ -const bool GeomAlgoAPI_Extrusion::isValid() const -{ - BRepCheck_Analyzer aChecker(myShape->impl()); - return (aChecker.IsValid() == Standard_True); -} - -//============================================================================ -const bool GeomAlgoAPI_Extrusion::hasVolume() const -{ - bool hasVolume(false); - if(isValid()) { - const TopoDS_Shape& aRShape = myShape->impl(); - GProp_GProps aGProp; - BRepGProp::VolumeProperties(aRShape, aGProp); - if(aGProp.Mass() > Precision::Confusion()) - hasVolume = true; - } - return hasVolume; -} - -//============================================================================ -const std::shared_ptr& GeomAlgoAPI_Extrusion::shape () const -{ - return myShape; -} - -//============================================================================ -const std::shared_ptr& GeomAlgoAPI_Extrusion::firstShape() -{ - return myFirst; -} - -//============================================================================ -const std::shared_ptr& GeomAlgoAPI_Extrusion::lastShape() -{ - return myLast; -} - -//============================================================================ -void GeomAlgoAPI_Extrusion::mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const -{ - theMap = myMap; -} - -//============================================================================ -GeomAlgoAPI_MakeShape * GeomAlgoAPI_Extrusion::makeShape() const -{ - return myMkShape; -} - -//============================================================================ -GeomAlgoAPI_Extrusion::~GeomAlgoAPI_Extrusion() -{ - if (!empty()) { - myMap.clear(); - } -} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.h b/src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.h deleted file mode 100644 index 0ac301469..000000000 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.h +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: GeomAlgoAPI_Extrusion.h -// Created: 22 October 2014 -// Author: Sergey Zaritchny - -#ifndef GeomAlgoAPI_Extrusion_H_ -#define GeomAlgoAPI_Extrusion_H_ - -#include -#include -#include -#include -#include -#include - -/**\class GeomAlgoAPI_Extrusion - * \ingroup DataAlgo - * \brief Allows to create the prism based on a given face and a direction - */ - -class GeomAlgoAPI_Extrusion : public GeomAPI_Interface -{ - public: - - /* \brief Creates extrusion for the given shape along the normal for this shape - * \param[in] theBasis face or wire to be extruded - * \param[in] theSize the length of extrusion (if the value is less than 0, the extrusion in opposite normal) - * \return a solid or a face/shell which is obtained from specified one - */ - /// Constructor - GEOMALGOAPI_EXPORT GeomAlgoAPI_Extrusion (std::shared_ptr theBasis, double theSize); - - /// Returns True if algorithm succeed - GEOMALGOAPI_EXPORT const bool isDone() const; - - /// Returns True if resulting shape is valid - GEOMALGOAPI_EXPORT const bool isValid() const; - - /// Returns True if resulting shape has volume - GEOMALGOAPI_EXPORT const bool hasVolume() const; - - /// Returns result of the Extrusion algorithm which may be a Solid or a Face - GEOMALGOAPI_EXPORT const std::shared_ptr& shape () const; - - /// Returns the first shape - GEOMALGOAPI_EXPORT const std::shared_ptr& firstShape(); - - /// returns last shape - GEOMALGOAPI_EXPORT const std::shared_ptr& lastShape(); - - /// Returns map of sub-shapes of the result. To be used for History keeping - GEOMALGOAPI_EXPORT void mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const; - - /// Return interface for for History processing - GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShape* makeShape () const; - - /// Destructor - GEOMALGOAPI_EXPORT ~GeomAlgoAPI_Extrusion(); -private: - /// builds resulting shape - void build(const std::shared_ptr& theBasis); - /// fields - double mySize; - bool myDone; - std::shared_ptr myShape; - std::shared_ptr myFirst; - std::shared_ptr myLast; - GeomAPI_DataMapOfShapeShape myMap; - GeomAlgoAPI_MakeShape * myMkShape; -}; - -#endif diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Movement.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Movement.cpp deleted file mode 100644 index 9bef39222..000000000 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Movement.cpp +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: GeomAlgoAPI_Movement.cpp -// Created: 8 June 2015 -// Author: Dmitry Bobylev - -#include - -#include - -#include -#include -#include -#include -#include - -//================================================================================================= -GeomAlgoAPI_Movement::GeomAlgoAPI_Movement(std::shared_ptr theSourceShape, - std::shared_ptr theAxis, - double theDistance, - bool theSimpleTransform) -: myDone(false) -{ - build(theSourceShape, theAxis, theDistance, theSimpleTransform); -} - -//================================================================================================= -void GeomAlgoAPI_Movement::build(std::shared_ptr theSourceShape, - std::shared_ptr theAxis, - double theDistance, - bool theSimpleTransform) -{ - if(!theSourceShape || !theAxis) { - return; - } - - const TopoDS_Shape& aSourceShape = theSourceShape->impl(); - const gp_Ax1& anAxis = theAxis->impl(); - - if(aSourceShape.IsNull()) { - return; - } - - gp_Trsf aTrsf; - aTrsf.SetTranslation(gp_Vec(anAxis.Direction()) * theDistance); - - TopoDS_Shape aResult; - // Transform the shape with copying it. - if (theSimpleTransform) { - TopLoc_Location aDelta(aTrsf); - aResult = aSourceShape.Moved(aDelta); - // store the accumulated information about the result and this delta - //myTrsf = std::shared_ptr(new GeomAPI_Trsf(new gp_Trsf(aTrsf * aSourceShape.Location().Transformation()))); - myTrsf = std::shared_ptr(new GeomAPI_Trsf(new gp_Trsf(aTrsf))); - myDone = true; // is OK for sure - } else { - BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, aTrsf, true); - if(!aBuilder) { - return; - } - myMkShape.reset(new GeomAlgoAPI_MakeShape(aBuilder)); - - myDone = aBuilder->IsDone() == Standard_True; - - if(!myDone) { - return; - } - - aResult = aBuilder->Shape(); - // Fill data map to keep correct orientation of sub-shapes. - myMap.reset(new GeomAPI_DataMapOfShapeShape()); - for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More(); anExp.Next()) { - std::shared_ptr aCurrentShape(new GeomAPI_Shape()); - aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current())); - myMap->bind(aCurrentShape, aCurrentShape); - } - } - - myShape.reset(new GeomAPI_Shape()); - myShape->setImpl(new TopoDS_Shape(aResult)); -} - -//================================================================================================= -const bool GeomAlgoAPI_Movement::isValid() const -{ - BRepCheck_Analyzer aChecker(myShape->impl()); - return (aChecker.IsValid() == Standard_True); -} - -//================================================================================================= -const bool GeomAlgoAPI_Movement::hasVolume() const -{ - bool hasVolume(false); - if(isValid() && (GeomAlgoAPI_ShapeTools::volume(myShape) > Precision::Confusion())) { - hasVolume = true; - } - return hasVolume; -} - -//================================================================================================= -const std::shared_ptr& GeomAlgoAPI_Movement::shape() const -{ - return myShape; -} - -//================================================================================================= -std::shared_ptr GeomAlgoAPI_Movement::mapOfShapes() const -{ - return myMap; -} - -//================================================================================================= -std::shared_ptr GeomAlgoAPI_Movement::makeShape() const -{ - return myMkShape; -} - -//================================================================================================= -std::shared_ptr GeomAlgoAPI_Movement::transformation() const -{ - return myTrsf; -} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Movement.h b/src/GeomAlgoAPI/GeomAlgoAPI_Movement.h deleted file mode 100644 index e3cced35b..000000000 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Movement.h +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: GeomAlgoAPI_Movement.h -// Created: 8 June 2015 -// Author: Dmitry Bobylev - -#ifndef GeomAlgoAPI_Movement_H_ -#define GeomAlgoAPI_Movement_H_ - -#include -#include -#include -#include -#include -#include - -/** \class GeomAlgoAPI_Movement - * \ingroup DataAlgo - * \brief Creates a copy of the object by moving it along the axis. - */ -class GeomAlgoAPI_Movement : public GeomAPI_Interface -{ -public: - /** \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. - * \param[in] theDistance movement distance. - * \param[in] theSimpleTransform makes just transformation of shape without changing of topology or geometry - */ - GEOMALGOAPI_EXPORT GeomAlgoAPI_Movement(std::shared_ptr theSourceShape, - std::shared_ptr theAxis, - double theDistance, - bool theSimpleTransform = false); - - /// \return true if algorithm succeed. - GEOMALGOAPI_EXPORT const bool isDone() const - { return myDone; } - - /// \return true if resulting shape is valid. - GEOMALGOAPI_EXPORT const bool isValid() const; - - /// \return true if resulting shape has volume. - GEOMALGOAPI_EXPORT const bool hasVolume() const; - - /// \return result of the movement algorithm. - GEOMALGOAPI_EXPORT const std::shared_ptr& shape() const; - - /// \return map of sub-shapes of the result. To be used for History keeping. - GEOMALGOAPI_EXPORT std::shared_ptr mapOfShapes() const; - - /// \return interface for for History processing. - GEOMALGOAPI_EXPORT std::shared_ptr makeShape() const; - - /// Returns the simple transformation - GEOMALGOAPI_EXPORT std::shared_ptr transformation() const; - -private: - /// Builds resulting shape. - void build(std::shared_ptr theSourceShape, - std::shared_ptr theAxis, - double theDistance, - bool theSimpleTransform); - -private: - /// Fields. - bool myDone; - std::shared_ptr myShape; - std::shared_ptr myMap; - std::shared_ptr myMkShape; - std::shared_ptr myTrsf; ///< transformation of the shape in case theSimpleTransform -}; - -#endif diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Translation.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Translation.cpp new file mode 100644 index 000000000..b9cc3b690 --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Translation.cpp @@ -0,0 +1,122 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomAlgoAPI_Translation.cpp +// Created: 8 June 2015 +// Author: Dmitry Bobylev + +#include + +#include + +#include +#include +#include +#include +#include + +//================================================================================================= +GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr theSourceShape, + std::shared_ptr theAxis, + double theDistance, + bool theSimpleTransform) +: myDone(false) +{ + build(theSourceShape, theAxis, theDistance, theSimpleTransform); +} + +//================================================================================================= +void GeomAlgoAPI_Translation::build(std::shared_ptr theSourceShape, + std::shared_ptr theAxis, + double theDistance, + bool theSimpleTransform) +{ + if(!theSourceShape || !theAxis) { + return; + } + + const TopoDS_Shape& aSourceShape = theSourceShape->impl(); + const gp_Ax1& anAxis = theAxis->impl(); + + if(aSourceShape.IsNull()) { + return; + } + + gp_Trsf aTrsf; + aTrsf.SetTranslation(gp_Vec(anAxis.Direction()) * theDistance); + + TopoDS_Shape aResult; + // Transform the shape with copying it. + if (theSimpleTransform) { + TopLoc_Location aDelta(aTrsf); + aResult = aSourceShape.Moved(aDelta); + // store the accumulated information about the result and this delta + //myTrsf = std::shared_ptr(new GeomAPI_Trsf(new gp_Trsf(aTrsf * aSourceShape.Location().Transformation()))); + myTrsf = std::shared_ptr(new GeomAPI_Trsf(new gp_Trsf(aTrsf))); + myDone = true; // is OK for sure + } else { + BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, aTrsf, true); + if(!aBuilder) { + return; + } + myMkShape.reset(new GeomAlgoAPI_MakeShape(aBuilder)); + + myDone = aBuilder->IsDone() == Standard_True; + + if(!myDone) { + return; + } + + aResult = aBuilder->Shape(); + // Fill data map to keep correct orientation of sub-shapes. + myMap.reset(new GeomAPI_DataMapOfShapeShape()); + for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More(); anExp.Next()) { + std::shared_ptr aCurrentShape(new GeomAPI_Shape()); + aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current())); + myMap->bind(aCurrentShape, aCurrentShape); + } + } + + myShape.reset(new GeomAPI_Shape()); + myShape->setImpl(new TopoDS_Shape(aResult)); +} + +//================================================================================================= +const bool GeomAlgoAPI_Translation::isValid() const +{ + BRepCheck_Analyzer aChecker(myShape->impl()); + return (aChecker.IsValid() == Standard_True); +} + +//================================================================================================= +const bool GeomAlgoAPI_Translation::hasVolume() const +{ + bool hasVolume(false); + if(isValid() && (GeomAlgoAPI_ShapeTools::volume(myShape) > Precision::Confusion())) { + hasVolume = true; + } + return hasVolume; +} + +//================================================================================================= +const std::shared_ptr& GeomAlgoAPI_Translation::shape() const +{ + return myShape; +} + +//================================================================================================= +std::shared_ptr GeomAlgoAPI_Translation::mapOfShapes() const +{ + return myMap; +} + +//================================================================================================= +std::shared_ptr GeomAlgoAPI_Translation::makeShape() const +{ + return myMkShape; +} + +//================================================================================================= +std::shared_ptr GeomAlgoAPI_Translation::transformation() const +{ + return myTrsf; +} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Translation.h b/src/GeomAlgoAPI/GeomAlgoAPI_Translation.h new file mode 100644 index 000000000..95f9c55f7 --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Translation.h @@ -0,0 +1,73 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomAlgoAPI_Translation.h +// Created: 8 June 2015 +// Author: Dmitry Bobylev + +#ifndef GeomAlgoAPI_Translation_H_ +#define GeomAlgoAPI_Translation_H_ + +#include +#include +#include +#include +#include +#include + +/** \class GeomAlgoAPI_Translation + * \ingroup DataAlgo + * \brief Creates a copy of the object by moving it along the axis. + */ +class GeomAlgoAPI_Translation : public GeomAPI_Interface +{ +public: + /** \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. + * \param[in] theDistance movement distance. + * \param[in] theSimpleTransform makes just transformation of shape without changing of topology or geometry + */ + GEOMALGOAPI_EXPORT GeomAlgoAPI_Translation(std::shared_ptr theSourceShape, + std::shared_ptr theAxis, + double theDistance, + bool theSimpleTransform = false); + + /// \return true if algorithm succeed. + GEOMALGOAPI_EXPORT const bool isDone() const + { return myDone; } + + /// \return true if resulting shape is valid. + GEOMALGOAPI_EXPORT const bool isValid() const; + + /// \return true if resulting shape has volume. + GEOMALGOAPI_EXPORT const bool hasVolume() const; + + /// \return result of the movement algorithm. + GEOMALGOAPI_EXPORT const std::shared_ptr& shape() const; + + /// \return map of sub-shapes of the result. To be used for History keeping. + GEOMALGOAPI_EXPORT std::shared_ptr mapOfShapes() const; + + /// \return interface for for History processing. + GEOMALGOAPI_EXPORT std::shared_ptr makeShape() const; + + /// Returns the simple transformation + GEOMALGOAPI_EXPORT std::shared_ptr transformation() const; + +private: + /// Builds resulting shape. + void build(std::shared_ptr theSourceShape, + std::shared_ptr theAxis, + double theDistance, + bool theSimpleTransform); + +private: + /// Fields. + bool myDone; + std::shared_ptr myShape; + std::shared_ptr myMap; + std::shared_ptr myMkShape; + std::shared_ptr myTrsf; ///< transformation of the shape in case theSimpleTransform +}; + +#endif diff --git a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp index ec7938b89..842eceba4 100644 --- a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp +++ b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp @@ -88,7 +88,7 @@ gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theShape, std::shared_ptr aDir = thePrs->plane()->dirX(); aVec1 = gp_Vec(aDir->impl()); } - gp_Vec aShift = aVec1.Crossed(thePrs->plane()->norm()->impl()); + gp_Vec aShift = aVec1.Crossed(thePrs->plane()->normal()->impl()); aShift.Normalize(); aShift.Multiply(theStep * 0.8); diff --git a/src/SketcherPrs/SketcherPrs_Radius.cpp b/src/SketcherPrs/SketcherPrs_Radius.cpp index 011555ffa..9a1ac1676 100644 --- a/src/SketcherPrs/SketcherPrs_Radius.cpp +++ b/src/SketcherPrs/SketcherPrs_Radius.cpp @@ -83,7 +83,7 @@ void SketcherPrs_Radius::Compute(const Handle(PrsMgr_PresentationManager3d)& the aRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt()); } std::shared_ptr aCenter = myPlane->to3D(aCenterAttr->x(), aCenterAttr->y()); - std::shared_ptr aNormal = myPlane->norm(); + std::shared_ptr aNormal = myPlane->normal(); GeomAPI_Circ aCircle(aCenter, aNormal, aRadius);