From dacb05dcf5c8ad153d2bf05bbca8dccb67ba3a2f Mon Sep 17 00:00:00 2001 From: dbv Date: Fri, 11 Sep 2015 15:56:24 +0300 Subject: [PATCH] ExtrusionSketch and RevolutionSketch features. --- src/Config/Config_Keywords.h | 5 + src/FeaturesPlugin/CMakeLists.txt | 8 + .../FeaturesPlugin_CompositeSketch.cpp | 206 ++++++++++++++++++ .../FeaturesPlugin_CompositeSketch.h | 87 ++++++++ .../FeaturesPlugin_ExtrusionSketch.cpp | 95 ++++++++ .../FeaturesPlugin_ExtrusionSketch.h | 98 +++++++++ src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp | 6 + .../FeaturesPlugin_RevolutionSketch.cpp | 112 ++++++++++ .../FeaturesPlugin_RevolutionSketch.h | 105 +++++++++ src/FeaturesPlugin/extrusionsketch_widget.xml | 69 ++++++ src/FeaturesPlugin/plugin-Features.xml | 6 + .../revolutionsketch_widget.xml | 85 ++++++++ src/PartSet/PartSet_WidgetSketchCreator.cpp | 65 +++--- src/PartSet/PartSet_WidgetSketchCreator.h | 3 + src/PartSet/PartSet_icons.qrc | 2 + src/PartSet/icons/extrusionsketch.png | Bin 0 -> 624 bytes src/PartSet/icons/revolsketch.png | Bin 0 -> 735 bytes 17 files changed, 925 insertions(+), 27 deletions(-) create mode 100644 src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp create mode 100644 src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.h create mode 100644 src/FeaturesPlugin/FeaturesPlugin_ExtrusionSketch.cpp create mode 100644 src/FeaturesPlugin/FeaturesPlugin_ExtrusionSketch.h create mode 100644 src/FeaturesPlugin/FeaturesPlugin_RevolutionSketch.cpp create mode 100644 src/FeaturesPlugin/FeaturesPlugin_RevolutionSketch.h create mode 100644 src/FeaturesPlugin/extrusionsketch_widget.xml create mode 100644 src/FeaturesPlugin/revolutionsketch_widget.xml create mode 100644 src/PartSet/icons/extrusionsketch.png create mode 100644 src/PartSet/icons/revolsketch.png diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index 0fdc9050f..7bbeef48e 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -114,4 +114,9 @@ const static char* NODE_ICON = "icon"; const static char* SHOW_EMPTY = "show_empty"; const static char* LINK_ITEM = "from_result"; +/* + * Hardcoded xml entities for composite features + */ +const static char* USE_BODY = "use_body"; + #endif /* CONFIG_KEYWORDS_H_ */ diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 149349075..6e5948606 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -15,9 +15,12 @@ SET(PROJECT_HEADERS FeaturesPlugin_Partition.h FeaturesPlugin_Placement.h FeaturesPlugin_CompositeBoolean.h + FeaturesPlugin_CompositeSketch.h FeaturesPlugin_ExtrusionBoolean.h + FeaturesPlugin_ExtrusionSketch.h FeaturesPlugin_ExtrusionCut.h FeaturesPlugin_ExtrusionFuse.h + FeaturesPlugin_RevolutionSketch.h FeaturesPlugin_RevolutionBoolean.h FeaturesPlugin_RevolutionCut.h FeaturesPlugin_RevolutionFuse.h @@ -34,9 +37,12 @@ SET(PROJECT_SOURCES FeaturesPlugin_Partition.cpp FeaturesPlugin_Placement.cpp FeaturesPlugin_CompositeBoolean.cpp + FeaturesPlugin_CompositeSketch.cpp + FeaturesPlugin_ExtrusionSketch.cpp FeaturesPlugin_ExtrusionBoolean.cpp FeaturesPlugin_ExtrusionCut.cpp FeaturesPlugin_ExtrusionFuse.cpp + FeaturesPlugin_RevolutionSketch.cpp FeaturesPlugin_RevolutionBoolean.cpp FeaturesPlugin_RevolutionCut.cpp FeaturesPlugin_RevolutionFuse.cpp @@ -45,9 +51,11 @@ SET(PROJECT_SOURCES SET(XML_RESOURCES plugin-Features.xml extrusion_widget.xml + extrusionsketch_widget.xml extrusioncut_widget.xml extrusionfuse_widget.xml revolution_widget.xml + revolutionsketch_widget.xml revolutioncut_widget.xml revolutionfuse_widget.xml rotation_widget.xml diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp new file mode 100644 index 000000000..f2edb24b4 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp @@ -0,0 +1,206 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: FeaturesPlugin_CompositeSketch.cpp +// Created: 11 September 2015 +// Author: Dmitry Bobylev + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +//================================================================================================= +void FeaturesPlugin_CompositeSketch::initAttributes() +{ + data()->addAttribute(SKETCH_OBJECT_ID(), ModelAPI_AttributeReference::typeId()); + data()->addAttribute(SKETCH_SELECTION_ID(), ModelAPI_AttributeSelection::typeId()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), SKETCH_SELECTION_ID()); + + initMakeSolidsAttributes(); +} + +//================================================================================================= +std::shared_ptr FeaturesPlugin_CompositeSketch::addFeature(std::string theID) +{ + std::shared_ptr aNew = document()->addFeature(theID, false); + if (aNew) { + data()->reference(SKETCH_OBJECT_ID())->setValue(aNew); + } + // set as current also after it becomes sub to set correctly enabled for other sketch subs + document()->setCurrentFeature(aNew, false); + return aNew; +} + +//================================================================================================= +int FeaturesPlugin_CompositeSketch::numberOfSubs(bool forTree) const +{ + ObjectPtr aObj = data()->reference(SKETCH_OBJECT_ID())->value(); + return aObj.get()? 1 : 0; +} + +//================================================================================================= +std::shared_ptr FeaturesPlugin_CompositeSketch::subFeature(const int theIndex, bool forTree) +{ + if (theIndex == 0) + return std::dynamic_pointer_cast(data()->reference(SKETCH_OBJECT_ID())->value()); + return std::shared_ptr(); +} + +//================================================================================================= +int FeaturesPlugin_CompositeSketch::subFeatureId(const int theIndex) const +{ + if (theIndex == 0) { + FeaturePtr aFeature = + std::dynamic_pointer_cast(data()->reference(SKETCH_OBJECT_ID())->value()); + if (aFeature.get()) + return aFeature->data()->featureId(); + } + return -1; +} + +//================================================================================================= +bool FeaturesPlugin_CompositeSketch::isSub(ObjectPtr theObject) const +{ + // check is this feature of result + FeaturePtr aFeature = std::dynamic_pointer_cast(theObject); + if (!aFeature) + return false; + + ObjectPtr aSub = data()->reference(SKETCH_OBJECT_ID())->value(); + return aSub == theObject; +} + +//================================================================================================= +void FeaturesPlugin_CompositeSketch::removeFeature(std::shared_ptr theFeature) +{ +} + +//================================================================================================= +void FeaturesPlugin_CompositeSketch::erase() +{ + if (data().get() && data()->isValid()) { // on abort of sketch of this composite it may be invalid + FeaturePtr aSketch = + std::dynamic_pointer_cast(data()->reference(SKETCH_OBJECT_ID())->value()); + if (aSketch.get() && aSketch->data()->isValid()) { + document()->removeFeature(aSketch); + } + } + ModelAPI_CompositeFeature::erase(); +} + + +//================================================================================================= +void FeaturesPlugin_CompositeSketch::execute() +{ + // Getting faces to create solids. + std::shared_ptr aSketchFeature = std::dynamic_pointer_cast( + reference(SKETCH_OBJECT_ID())->value()); + if(!aSketchFeature || aSketchFeature->results().empty()) { + return; + } + ResultPtr aSketchRes = aSketchFeature->results().front(); + ResultConstructionPtr aConstruction = std::dynamic_pointer_cast(aSketchRes); + if(!aConstruction.get()) { + return; + } + selection(SKETCH_SELECTION_ID())->setValue(aSketchRes, std::shared_ptr()); + int aSketchFacesNum = aConstruction->facesNum(); + if(aSketchFacesNum == 0) { + return; + } + ListOfShape aFacesList; + for(int aFaceIndex = 0; aFaceIndex < aSketchFacesNum; aFaceIndex++) { + std::shared_ptr aFace = std::dynamic_pointer_cast(aConstruction->face(aFaceIndex)); + aFacesList.push_back(aFace); + } + + // Searching faces with common edges. + ListOfShape aShells; + ListOfShape aFreeFaces; + std::shared_ptr aFacesCompound = GeomAlgoAPI_CompoundBuilder::compound(aFacesList); + GeomAlgoAPI_ShapeTools::combineShapes(aFacesCompound, GeomAPI_Shape::SHELL, aShells, aFreeFaces); + aShells.insert(aShells.end(), aFreeFaces.begin(), aFreeFaces.end()); + + // Generating result for each shell and face. + int aErrorsNum = 0; + int aResultIndex = 0; + for(ListOfShape::const_iterator anIter = aShells.cbegin(); anIter != aShells.cend(); anIter++) { + std::shared_ptr aResult; + ListOfShape aFromFaces, aToFaces; + std::shared_ptr aMakeShape; + std::shared_ptr aDataMap; + + std::shared_ptr aBaseFace = *anIter; + makeSolid(aBaseFace, aResult, aFromFaces, aToFaces, aMakeShape, aDataMap); + if(!aResult.get()) { + aErrorsNum++; + continue; + } + + ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); + loadNamingDS(aResultBody, aBaseFace, aResult, aFromFaces, aToFaces, aMakeShape, aDataMap); + setResult(aResultBody, aResultIndex); + aResultIndex++; + } + + if(aErrorsNum > 0) { + std::ostringstream aStringStream; + aStringStream << "Warning: could not create solid(s) from " << aErrorsNum << " face(s)."; + setError(aStringStream.str()); + } + + // Remove the rest results if there were produced in the previous pass. + removeResults(aResultIndex); +} + +//================================================================================================= +void FeaturesPlugin_CompositeSketch::loadNamingDS(std::shared_ptr theResultBody, + const std::shared_ptr& theBaseShape, + const std::shared_ptr& theResult, + const ListOfShape& theFromFaces, + const ListOfShape& theToFaces, + const std::shared_ptr& theMakeShape, + const std::shared_ptr& theDataMap) +{ + //load result + theResultBody->storeGenerated(theBaseShape, theResult); + + //Insert lateral face : Face from Edge + const std::string aLatName = "LateralFace"; + const int aLatTag = 1; + theResultBody->loadAndOrientGeneratedShapes(theMakeShape.get(), theBaseShape, GeomAPI_Shape::EDGE, aLatTag, aLatName, *theDataMap); + + //Insert to faces + const std::string aToName = "ToFace"; + int aToTag = 2; + for(ListOfShape::const_iterator anIt = theToFaces.cbegin(); anIt != theToFaces.cend(); anIt++) { + std::shared_ptr aToFace = *anIt; + if(theDataMap->isBound(aToFace)) { + aToFace = theDataMap->find(aToFace); + } + theResultBody->generated(aToFace, aToName, aToTag++); + } + + //Insert from faces + const std::string aFromName = "FromFace"; + int aFromTag = aToTag > 10000 ? aToTag : 10000; + for(ListOfShape::const_iterator anIt = theFromFaces.cbegin(); anIt != theFromFaces.cend(); anIt++) { + std::shared_ptr aFromFace = *anIt; + if(theDataMap->isBound(aFromFace)) { + aFromFace = theDataMap->find(aFromFace); + } + theResultBody->generated(aFromFace, aFromName, aFromTag++); + } +} diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.h b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.h new file mode 100644 index 000000000..ed3f32437 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.h @@ -0,0 +1,87 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: FeaturesPlugin_CompositeSketch.h +// Created: 11 September 2015 +// Author: Dmitry Bobylev + +#ifndef FeaturesPlugin_CompositeSketch_H_ +#define FeaturesPlugin_CompositeSketch_H_ + +#include + +#include + +#include + +/** \class FeaturesPlugin_CompositeSketch + * \ingroup Plugins + */ +class FeaturesPlugin_CompositeSketch : public ModelAPI_CompositeFeature +{ + public: + /// Attribute name of sketch feature. + inline static const std::string& SKETCH_OBJECT_ID() + { + static const std::string MY_SKETCH_OBJECT_ID("sketch"); + return MY_SKETCH_OBJECT_ID; + } + + /// Attribute name of sketch feature. + inline static const std::string& SKETCH_SELECTION_ID() + { + static const std::string MY_SKETCH_SELECTION_ID("sketch_selection"); + return MY_SKETCH_SELECTION_ID; + } + + /// 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(); + + /// Appends a feature to the sketch sub-elements container. + FEATURESPLUGIN_EXPORT virtual std::shared_ptr addFeature(std::string theID); + + /// \return the number of sub-elements. + FEATURESPLUGIN_EXPORT virtual int numberOfSubs(bool forTree = false) const; + + /// \return the sub-feature by zero-base index. + FEATURESPLUGIN_EXPORT virtual std::shared_ptr subFeature(const int theIndex, bool forTree = false); + + /// \return the sub-feature unique identifier in this composite feature by zero-base index. + FEATURESPLUGIN_EXPORT virtual int subFeatureId(const int theIndex) const; + + /// \return true if feature or reuslt belong to this composite feature as subs. + FEATURESPLUGIN_EXPORT virtual bool isSub(ObjectPtr theObject) const; + + /// This method to inform that sub-feature is removed and must be removed from the internal data + /// structures of the owner (the remove from the document will be done outside just after) + FEATURESPLUGIN_EXPORT virtual void removeFeature(std::shared_ptr theFeature); + + /// removes also all sub-sketch + FEATURESPLUGIN_EXPORT virtual void erase(); + +protected: + FeaturesPlugin_CompositeSketch(){}; + + /// Define this function to init attributes for extrusion/revolution. + virtual void initMakeSolidsAttributes() = 0; + + /// Define this function to create solids from faces with extrusion/revolution. + virtual void makeSolid(const std::shared_ptr theFace, + std::shared_ptr& theResult, + ListOfShape& theFromFaces, + ListOfShape& theToFaces, + std::shared_ptr& theMakeShape, + std::shared_ptr& theDataMap) = 0; + + void loadNamingDS(std::shared_ptr theResultBody, + const std::shared_ptr& theBaseShape, + const std::shared_ptr& theResult, + const ListOfShape& theFromFaces, + const ListOfShape& theToFaces, + const std::shared_ptr& theMakeShape, + const std::shared_ptr& theDataMap); +}; + +#endif diff --git a/src/FeaturesPlugin/FeaturesPlugin_ExtrusionSketch.cpp b/src/FeaturesPlugin/FeaturesPlugin_ExtrusionSketch.cpp new file mode 100644 index 000000000..682ea60ac --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_ExtrusionSketch.cpp @@ -0,0 +1,95 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: FeaturesPlugin_ExtrusionSketch.cpp +// Created: 11 September 2015 +// Author: Dmitry Bobylev + +#include + +#include +#include +#include +#include +#include + +#include + +//================================================================================================= +FeaturesPlugin_ExtrusionSketch::FeaturesPlugin_ExtrusionSketch() +{ +} + +//================================================================================================= +void FeaturesPlugin_ExtrusionSketch::initMakeSolidsAttributes() +{ + data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId()); + + data()->addAttribute(TO_SIZE_ID(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(FROM_SIZE_ID(), ModelAPI_AttributeDouble::typeId()); + + data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(TO_OFFSET_ID(), ModelAPI_AttributeDouble::typeId()); + + data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(FROM_OFFSET_ID(), ModelAPI_AttributeDouble::typeId()); + + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID()); +} + +//================================================================================================= +void FeaturesPlugin_ExtrusionSketch::makeSolid(const std::shared_ptr theFace, + std::shared_ptr& theResult, + ListOfShape& theFromFaces, + ListOfShape& theToFaces, + std::shared_ptr& theMakeShape, + std::shared_ptr& theDataMap) +{ + // Getting extrusion sizes. + double aToSize = 0.0; + double aFromSize = 0.0; + + if(string(CREATION_METHOD())->value() == "BySizes") { + aToSize = real(TO_SIZE_ID())->value(); + aFromSize = real(FROM_SIZE_ID())->value(); + } else { + aToSize = real(TO_OFFSET_ID())->value(); + aFromSize = real(FROM_OFFSET_ID())->value(); + } + + // Getting extrusion bounding planes. + std::shared_ptr aToShape; + std::shared_ptr aFromShape; + + if(string(CREATION_METHOD())->value() == "ByPlanesAndOffsets") { + std::shared_ptr anObjRef = selection(TO_OBJECT_ID()); + if(anObjRef.get() != NULL) { + aToShape = std::dynamic_pointer_cast(anObjRef->value()); + if(aToShape.get() == NULL && anObjRef->context().get() != NULL) { + aToShape = anObjRef->context()->shape(); + } + } + anObjRef = selection(FROM_OBJECT_ID()); + if(anObjRef.get() != NULL) { + aFromShape = std::dynamic_pointer_cast(anObjRef->value()); + if(aFromShape.get() == NULL && anObjRef->context().get() != NULL) { + aFromShape = anObjRef->context()->shape(); + } + } + } + + // Extrude face + GeomAlgoAPI_Prism aPrismAlgo(theFace, aToShape, aToSize, aFromShape, aFromSize); + + // Checking that the algorithm worked properly. + if(!aPrismAlgo.isDone() || !aPrismAlgo.shape().get() || aPrismAlgo.shape()->isNull() || + !aPrismAlgo.isValid()) { + return; + } + + theResult = aPrismAlgo.shape(); + theFromFaces = aPrismAlgo.fromFaces(); + theToFaces = aPrismAlgo.toFaces(); + theMakeShape = aPrismAlgo.makeShape(); + theDataMap = aPrismAlgo.mapOfShapes(); +} diff --git a/src/FeaturesPlugin/FeaturesPlugin_ExtrusionSketch.h b/src/FeaturesPlugin/FeaturesPlugin_ExtrusionSketch.h new file mode 100644 index 000000000..f9db7e535 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_ExtrusionSketch.h @@ -0,0 +1,98 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: FeaturesPlugin_ExtrusionSketch.h +// Created: 11 September 2015 +// Author: Dmitry Bobylev + +#ifndef FeaturesPlugin_ExtrusionSketch_H_ +#define FeaturesPlugin_ExtrusionSketch_H_ + +#include + +/** \class FeaturesPlugin_ExtrusionSketch + * \ingroup Plugins + */ +class FeaturesPlugin_ExtrusionSketch : public FeaturesPlugin_CompositeSketch +{ + public: + /// Feature kind. + inline static const std::string& ID() + { + static const std::string MY_EXTRUSION_ID("ExtrusionSketch"); + return MY_EXTRUSION_ID; + } + + /// \return the kind of a feature + FEATURESPLUGIN_EXPORT virtual const std::string& getKind() + { + static std::string MY_KIND = FeaturesPlugin_ExtrusionSketch::ID(); + return MY_KIND; + } + + /// attribute name for creation method + inline static const std::string& CREATION_METHOD() + { + static const std::string METHOD_ATTR("CreationMethod"); + return METHOD_ATTR; + } + + /// attribute name of extrusion size + inline static const std::string& TO_SIZE_ID() + { + static const std::string MY_TO_SIZE_ID("to_size"); + return MY_TO_SIZE_ID; + } + + /// attribute name of extrusion size + inline static const std::string& FROM_SIZE_ID() + { + static const std::string MY_FROM_SIZE_ID("from_size"); + return MY_FROM_SIZE_ID; + } + + /// attribute name of an object to which the extrusion grows. + inline static const std::string& TO_OBJECT_ID() + { + static const std::string MY_TO_OBJECT_ID("to_object"); + return MY_TO_OBJECT_ID; + } + + /// attribute name of extrusion offset + inline static const std::string& TO_OFFSET_ID() + { + static const std::string MY_TO_OFFSET_ID("to_offset"); + return MY_TO_OFFSET_ID; + } + + /// Attribute name of an object from which the extrusion grows. + inline static const std::string& FROM_OBJECT_ID() + { + static const std::string MY_FROM_OBJECT_ID("from_object"); + return MY_FROM_OBJECT_ID; + } + + /// attribute name of extrusion offset + inline static const std::string& FROM_OFFSET_ID() + { + static const std::string MY_FROM_OFFSET_ID("from_offset"); + return MY_FROM_OFFSET_ID; + } + +protected: + /// Init attributes for extrusion. + virtual void initMakeSolidsAttributes(); + + /// Create solid from face with extrusion. + virtual void makeSolid(const std::shared_ptr theFace, + std::shared_ptr& theResult, + ListOfShape& theFromFaces, + ListOfShape& theToFaces, + std::shared_ptr& theMakeShape, + std::shared_ptr& theDataMap); + +public: + /// Use plugin manager for features creation. + FeaturesPlugin_ExtrusionSketch(); +}; + +#endif diff --git a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp index c8ab834cc..a92358003 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -11,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -58,6 +60,10 @@ FeaturePtr FeaturesPlugin_Plugin::createFeature(string theFeatureID) return FeaturePtr(new FeaturesPlugin_RevolutionCut); } else if (theFeatureID == FeaturesPlugin_RevolutionFuse::ID()) { return FeaturePtr(new FeaturesPlugin_RevolutionFuse); + } else if (theFeatureID == FeaturesPlugin_ExtrusionSketch::ID()) { + return FeaturePtr(new FeaturesPlugin_ExtrusionSketch); + } else if (theFeatureID == FeaturesPlugin_RevolutionSketch::ID()) { + return FeaturePtr(new FeaturesPlugin_RevolutionSketch); } // feature of such kind is not found return FeaturePtr(); diff --git a/src/FeaturesPlugin/FeaturesPlugin_RevolutionSketch.cpp b/src/FeaturesPlugin/FeaturesPlugin_RevolutionSketch.cpp new file mode 100644 index 000000000..454e658ba --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_RevolutionSketch.cpp @@ -0,0 +1,112 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: FeaturesPlugin_RevolutionSketch.cpp +// Created: 11 September 2015 +// Author: Dmitry Bobylev + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +//================================================================================================= +FeaturesPlugin_RevolutionSketch::FeaturesPlugin_RevolutionSketch() +{ +} + +//================================================================================================= +void FeaturesPlugin_RevolutionSketch::initMakeSolidsAttributes() +{ + data()->addAttribute(FeaturesPlugin_RevolutionSketch::AXIS_OBJECT_ID(), ModelAPI_AttributeSelection::typeId()); + + data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId()); + + data()->addAttribute(TO_ANGLE_ID(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(FROM_ANGLE_ID(), ModelAPI_AttributeDouble::typeId()); + + data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(TO_OFFSET_ID(), ModelAPI_AttributeDouble::typeId()); + + data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(FROM_OFFSET_ID(), ModelAPI_AttributeDouble::typeId()); + + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID()); +} + +//================================================================================================= +void FeaturesPlugin_RevolutionSketch::makeSolid(const std::shared_ptr theFace, + std::shared_ptr& theResult, + ListOfShape& theFromFaces, + ListOfShape& theToFaces, + std::shared_ptr& theMakeShape, + std::shared_ptr& theDataMap) +{ + //Getting axis. + std::shared_ptr anAxis; + std::shared_ptr anEdge; + std::shared_ptr anObjRef = selection(FeaturesPlugin_RevolutionSketch::AXIS_OBJECT_ID()); + if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) { + anEdge = std::shared_ptr(new GeomAPI_Edge(anObjRef->value())); + } else if(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 revolution angles. + double aToAngle = real(TO_ANGLE_ID())->value(); + double aFromAngle = real(FROM_ANGLE_ID())->value(); + + if(string(CREATION_METHOD())->value() == "ByAngles") { + aToAngle = real(TO_ANGLE_ID())->value(); + aFromAngle = real(FROM_ANGLE_ID())->value(); + } else { + aToAngle = real(TO_OFFSET_ID())->value(); + aFromAngle = real(FROM_OFFSET_ID())->value(); + } + + // Getting revolution bounding planes. + std::shared_ptr aToShape; + std::shared_ptr aFromShape; + + if(string(CREATION_METHOD())->value() == "ByPlanesAndOffsets") { + anObjRef = selection(TO_OBJECT_ID()); + if(anObjRef.get() != NULL) { + aToShape = std::dynamic_pointer_cast(anObjRef->value()); + if(aToShape.get() == NULL && anObjRef->context().get() != NULL) { + aToShape = anObjRef->context()->shape(); + } + } + anObjRef = selection(FROM_OBJECT_ID()); + if(anObjRef.get() != NULL) { + aFromShape = std::dynamic_pointer_cast(anObjRef->value()); + if(aFromShape.get() == NULL && anObjRef->context().get() != NULL) { + aFromShape = anObjRef->context()->shape(); + } + } + } + + // Revol face + GeomAlgoAPI_Revolution aRevolAlgo(theFace, anAxis, aToShape, aToAngle, aFromShape, aFromAngle); + + // Checking that the algorithm worked properly. + if(!aRevolAlgo.isDone() || !aRevolAlgo.shape().get() || aRevolAlgo.shape()->isNull() || + !aRevolAlgo.isValid()) { + return; + } + + theResult = aRevolAlgo.shape(); + theFromFaces = aRevolAlgo.fromFaces(); + theToFaces = aRevolAlgo.toFaces(); + theMakeShape = aRevolAlgo.makeShape(); + theDataMap = aRevolAlgo.mapOfShapes(); +} diff --git a/src/FeaturesPlugin/FeaturesPlugin_RevolutionSketch.h b/src/FeaturesPlugin/FeaturesPlugin_RevolutionSketch.h new file mode 100644 index 000000000..b211c9222 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_RevolutionSketch.h @@ -0,0 +1,105 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: FeaturesPlugin_RevolutionSketch.h +// Created: 11 September 2015 +// Author: Dmitry Bobylev + +#ifndef FeaturesPlugin_RevolutionSketch_H_ +#define FeaturesPlugin_RevolutionSketch_H_ + +#include + +/** \class FeaturesPlugin_RevolutionSketch + * \ingroup Plugins + */ +class FeaturesPlugin_RevolutionSketch : public FeaturesPlugin_CompositeSketch +{ +public: + /// Feature kind. + inline static const std::string& ID() + { + static const std::string MY_REVOLUTION_ID("RevolutionSketch"); + return MY_REVOLUTION_ID; + } + + /// \return the kind of a feature + FEATURESPLUGIN_EXPORT virtual const std::string& getKind() + { + static std::string MY_KIND = FeaturesPlugin_RevolutionSketch::ID(); + return MY_KIND; + } + + /// Attribute name of an revolution axis. + inline static const std::string& AXIS_OBJECT_ID() + { + static const std::string MY_AXIS_ID("axis_object"); + return MY_AXIS_ID; + } + + /// attribute name for creation method + inline static const std::string& CREATION_METHOD() + { + static const std::string METHOD_ATTR("CreationMethod"); + return METHOD_ATTR; + } + + /// Attribute name of revolution to angle. + inline static const std::string& TO_ANGLE_ID() + { + static const std::string MY_TO_ANGLE_ID("to_angle"); + return MY_TO_ANGLE_ID; + } + + /// Attribute name of revolution from angle. + inline static const std::string& FROM_ANGLE_ID() + { + static const std::string MY_FROM_ANGLE_ID("from_angle"); + return MY_FROM_ANGLE_ID; + } + + /// Attribute name of an object to which the revolution grows. + inline static const std::string& TO_OBJECT_ID() + { + static const std::string MY_TO_OBJECT_ID("to_object"); + return MY_TO_OBJECT_ID; + } + + /// Attribute name of extrusion offset. + inline static const std::string& TO_OFFSET_ID() + { + static const std::string MY_TO_OFFSET_ID("to_offset"); + return MY_TO_OFFSET_ID; + } + + /// Attribute name of an object from which the revolution grows. + inline static const std::string& FROM_OBJECT_ID() + { + static const std::string MY_FROM_OBJECT_ID("from_object"); + return MY_FROM_OBJECT_ID; + } + + /// Attribute name of extrusion offset. + inline static const std::string& FROM_OFFSET_ID() + { + static const std::string MY_FROM_OFFSET_ID("from_offset"); + return MY_FROM_OFFSET_ID; + } + +protected: + /// Init attributes for revolution. + virtual void initMakeSolidsAttributes(); + + /// Create solids from faces with revolution. + virtual void makeSolid(const std::shared_ptr theFace, + std::shared_ptr& theResult, + ListOfShape& theFromFaces, + ListOfShape& theToFaces, + std::shared_ptr& theMakeShape, + std::shared_ptr& theDataMap); + +public: + /// Use plugin manager for features creation. + FeaturesPlugin_RevolutionSketch(); +}; + +#endif diff --git a/src/FeaturesPlugin/extrusionsketch_widget.xml b/src/FeaturesPlugin/extrusionsketch_widget.xml new file mode 100644 index 000000000..b95763321 --- /dev/null +++ b/src/FeaturesPlugin/extrusionsketch_widget.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/FeaturesPlugin/plugin-Features.xml b/src/FeaturesPlugin/plugin-Features.xml index 79f2f5843..6e85d82de 100644 --- a/src/FeaturesPlugin/plugin-Features.xml +++ b/src/FeaturesPlugin/plugin-Features.xml @@ -6,6 +6,9 @@ + + + @@ -17,6 +20,9 @@ + + + diff --git a/src/FeaturesPlugin/revolutionsketch_widget.xml b/src/FeaturesPlugin/revolutionsketch_widget.xml new file mode 100644 index 000000000..d2b6ac20a --- /dev/null +++ b/src/FeaturesPlugin/revolutionsketch_widget.xml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/PartSet/PartSet_WidgetSketchCreator.cpp b/src/PartSet/PartSet_WidgetSketchCreator.cpp index f7a52416e..347620630 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.cpp +++ b/src/PartSet/PartSet_WidgetSketchCreator.cpp @@ -7,6 +7,8 @@ #include "PartSet_WidgetSketchCreator.h" #include "PartSet_Module.h" +#include + #include #include #include @@ -39,7 +41,7 @@ PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent, PartSet_Module* theModule, const Config_WidgetAPI* theData, const std::string& theParentId) -: ModuleBase_ModelWidget(theParent, theData, theParentId), myModule(theModule) +: ModuleBase_ModelWidget(theParent, theData, theParentId), myModule(theModule), myUseBody(true) { QFormLayout* aLayout = new QFormLayout(this); ModuleBase_Tools::adjustMargins(aLayout); @@ -57,6 +59,11 @@ PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent, myTextLine->setToolTip(aToolTip); myTextLine->installEventFilter(this); + QString aUseBody = QString::fromStdString(theData->getProperty(USE_BODY)); + if(!aUseBody.isEmpty()) { + myUseBody = QVariant(aUseBody).toBool(); + } + aLayout->addRow(myLabel, myTextLine); } @@ -104,13 +111,15 @@ void PartSet_WidgetSketchCreator::onStarted() XGUI_Workshop* aWorkshop = aConnector->workshop(); XGUI_Displayer* aDisp = aWorkshop->displayer(); QObjectPtrList aObjList = aDisp->displayedObjects(); - bool aHasBody = false; + bool aHasBody = !myUseBody; ResultBodyPtr aBody; - foreach(ObjectPtr aObj, aObjList) { - aBody = std::dynamic_pointer_cast(aObj); - if (aBody.get() != NULL) { - aHasBody = true; - break; + if(!aHasBody) { + foreach(ObjectPtr aObj, aObjList) { + aBody = std::dynamic_pointer_cast(aObj); + if (aBody.get() != NULL) { + aHasBody = true; + break; + } } } @@ -184,26 +193,28 @@ void PartSet_WidgetSketchCreator::onResumed(ModuleBase_Operation* theOp) } aSketchFeature->setDisplayed(false); - // Add Selected body were created the sketcher to list of selected objects - DataPtr aData = aSketchFeature->data(); - AttributeSelectionPtr aSelAttr = - std::dynamic_pointer_cast - (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); - if (aSelAttr.get()) { - ResultPtr aRes = aSelAttr->context(); - GeomShapePtr aShape = aSelAttr->value(); - if (aRes.get()) { - std::string anObjectsAttribute = FeaturesPlugin_CompositeBoolean::BOOLEAN_OBJECTS_ID(); - SessionPtr aMgr = ModelAPI_Session::get(); - ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); - AttributePtr anAttribute = myFeature->attribute(anObjectsAttribute); - std::string aValidatorID, anError; - AttributeSelectionListPtr aSelList = aCompFeature->data()->selectionList(anObjectsAttribute); - aSelList->append(aRes, GeomShapePtr()); - if (aFactory->validate(anAttribute, aValidatorID, anError)) - updateObject(aCompFeature); - else - aSelList->clear(); + if(myUseBody) { + // Add Selected body were created the sketcher to list of selected objects + DataPtr aData = aSketchFeature->data(); + AttributeSelectionPtr aSelAttr = + std::dynamic_pointer_cast + (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); + if (aSelAttr.get()) { + ResultPtr aRes = aSelAttr->context(); + GeomShapePtr aShape = aSelAttr->value(); + if (aRes.get()) { + std::string anObjectsAttribute = FeaturesPlugin_CompositeBoolean::BOOLEAN_OBJECTS_ID(); + SessionPtr aMgr = ModelAPI_Session::get(); + ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + AttributePtr anAttribute = myFeature->attribute(anObjectsAttribute); + std::string aValidatorID, anError; + AttributeSelectionListPtr aSelList = aCompFeature->data()->selectionList(anObjectsAttribute); + aSelList->append(aRes, GeomShapePtr()); + if (aFactory->validate(anAttribute, aValidatorID, anError)) + updateObject(aCompFeature); + else + aSelList->clear(); + } } } } diff --git a/src/PartSet/PartSet_WidgetSketchCreator.h b/src/PartSet/PartSet_WidgetSketchCreator.h index adb5a92be..9bcc8a67f 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.h +++ b/src/PartSet/PartSet_WidgetSketchCreator.h @@ -63,6 +63,9 @@ private: /// Input control of the widget QLineEdit* myTextLine; + /// To check if we need to use body for composite feature or not + bool myUseBody; + }; #endif \ No newline at end of file diff --git a/src/PartSet/PartSet_icons.qrc b/src/PartSet/PartSet_icons.qrc index b9ab4319c..8361c656e 100644 --- a/src/PartSet/PartSet_icons.qrc +++ b/src/PartSet/PartSet_icons.qrc @@ -15,11 +15,13 @@ icons/duplicate.png icons/remove.png icons/extrusion.png + icons/extrusionsketch.png icons/cut.png icons/cut_tool.png icons/cut_shape.png icons/fusion.png icons/revol.png + icons/revolsketch.png icons/revol_cut.png icons/revol_fuse.png icons/common.png diff --git a/src/PartSet/icons/extrusionsketch.png b/src/PartSet/icons/extrusionsketch.png new file mode 100644 index 0000000000000000000000000000000000000000..17eddd787eb85af7362cac7c20a7072da6e3b0f9 GIT binary patch literal 624 zcmV-$0+0QPP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGh)&Kwv)&Y=jd7JpyA&jEa4XPh|@MmP|U@D z0#M%{U`Pi(5poEWhXp1f4AjH|#6Zpd;BWv5ycKiyUjd}o0`UeUyb*{&32F-x-U`IW zV48tx;~B_+f1)7lOdJMl1f@(De^4T`0vP}?jWi6(CrM&10gM3lG%l>P=NZoc0000< KMNUMnLSTXtoe?eo literal 0 HcmV?d00001 diff --git a/src/PartSet/icons/revolsketch.png b/src/PartSet/icons/revolsketch.png new file mode 100644 index 0000000000000000000000000000000000000000..2458102720bf55cea8401b2a00a848d970739f4c GIT binary patch literal 735 zcmV<50wDc~P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGh)&Kwv)&Y=jd7JgDO-^!do5A^49_3HFUeqcJ2lq1!9ddaGz1!B&vy1a$MV&IfA+gP*St zm%tN=+GC;~9&~qvbl#PJYP5Zc5BKQR1Wyy3-i3EPX%e4AM9YY1|>yDqOHcaia zXe@~6WMFcuKhzHK1)zP4nQP)V7Gh6FPiNPoR_?Q++nLsZb_5fygfw&5ol7FA?AMF8 zXDU}7&Q|u>XI3N0(W|~NU<|8rjO`b3AwD8eXH49YY6{(+g2@c&wQ>b9{P^Qi<-w~$ zMU9V?13DYR1$u+1OX6st2-d-$I={gSut