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_ */
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
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
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
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: FeaturesPlugin_CompositeSketch.cpp
+// Created: 11 September 2015
+// Author: Dmitry Bobylev
+
+#include <FeaturesPlugin_CompositeSketch.h>
+
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_BodyBuilder.h>
+#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
+
+#include <GeomAlgoAPI_CompoundBuilder.h>
+#include <GeomAlgoAPI_Prism.h>
+#include <GeomAlgoAPI_Revolution.h>
+#include <GeomAlgoAPI_ShapeTools.h>
+
+#include <sstream>
+
+//=================================================================================================
+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<ModelAPI_Feature> FeaturesPlugin_CompositeSketch::addFeature(std::string theID)
+{
+ std::shared_ptr<ModelAPI_Feature> 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<ModelAPI_Feature> FeaturesPlugin_CompositeSketch::subFeature(const int theIndex, bool forTree)
+{
+ if (theIndex == 0)
+ return std::dynamic_pointer_cast<ModelAPI_Feature>(data()->reference(SKETCH_OBJECT_ID())->value());
+ return std::shared_ptr<ModelAPI_Feature>();
+}
+
+//=================================================================================================
+int FeaturesPlugin_CompositeSketch::subFeatureId(const int theIndex) const
+{
+ if (theIndex == 0) {
+ FeaturePtr aFeature =
+ std::dynamic_pointer_cast<ModelAPI_Feature>(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<ModelAPI_Feature>(theObject);
+ if (!aFeature)
+ return false;
+
+ ObjectPtr aSub = data()->reference(SKETCH_OBJECT_ID())->value();
+ return aSub == theObject;
+}
+
+//=================================================================================================
+void FeaturesPlugin_CompositeSketch::removeFeature(std::shared_ptr<ModelAPI_Feature> 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<ModelAPI_Feature>(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<ModelAPI_Feature> aSketchFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(
+ reference(SKETCH_OBJECT_ID())->value());
+ if(!aSketchFeature || aSketchFeature->results().empty()) {
+ return;
+ }
+ ResultPtr aSketchRes = aSketchFeature->results().front();
+ ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aSketchRes);
+ if(!aConstruction.get()) {
+ return;
+ }
+ selection(SKETCH_SELECTION_ID())->setValue(aSketchRes, std::shared_ptr<GeomAPI_Shape>());
+ int aSketchFacesNum = aConstruction->facesNum();
+ if(aSketchFacesNum == 0) {
+ return;
+ }
+ ListOfShape aFacesList;
+ for(int aFaceIndex = 0; aFaceIndex < aSketchFacesNum; aFaceIndex++) {
+ std::shared_ptr<GeomAPI_Shape> aFace = std::dynamic_pointer_cast<GeomAPI_Shape>(aConstruction->face(aFaceIndex));
+ aFacesList.push_back(aFace);
+ }
+
+ // Searching faces with common edges.
+ ListOfShape aShells;
+ ListOfShape aFreeFaces;
+ std::shared_ptr<GeomAPI_Shape> 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<GeomAPI_Shape> aResult;
+ ListOfShape aFromFaces, aToFaces;
+ std::shared_ptr<GeomAlgoAPI_MakeShape> aMakeShape;
+ std::shared_ptr<GeomAPI_DataMapOfShapeShape> aDataMap;
+
+ std::shared_ptr<GeomAPI_Shape> 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<ModelAPI_ResultBody> theResultBody,
+ const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
+ const std::shared_ptr<GeomAPI_Shape>& theResult,
+ const ListOfShape& theFromFaces,
+ const ListOfShape& theToFaces,
+ const std::shared_ptr<GeomAlgoAPI_MakeShape>& theMakeShape,
+ const std::shared_ptr<GeomAPI_DataMapOfShapeShape>& 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<GeomAPI_Shape> 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<GeomAPI_Shape> aFromFace = *anIt;
+ if(theDataMap->isBound(aFromFace)) {
+ aFromFace = theDataMap->find(aFromFace);
+ }
+ theResultBody->generated(aFromFace, aFromName, aFromTag++);
+ }
+}
--- /dev/null
+// 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 <FeaturesPlugin.h>
+
+#include <ModelAPI_CompositeFeature.h>
+
+#include <GeomAlgoAPI_Boolean.h>
+
+/** \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<ModelAPI_Feature> 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<ModelAPI_Feature> 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<ModelAPI_Feature> 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<GeomAPI_Shape> theFace,
+ std::shared_ptr<GeomAPI_Shape>& theResult,
+ ListOfShape& theFromFaces,
+ ListOfShape& theToFaces,
+ std::shared_ptr<GeomAlgoAPI_MakeShape>& theMakeShape,
+ std::shared_ptr<GeomAPI_DataMapOfShapeShape>& theDataMap) = 0;
+
+ void loadNamingDS(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
+ const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
+ const std::shared_ptr<GeomAPI_Shape>& theResult,
+ const ListOfShape& theFromFaces,
+ const ListOfShape& theToFaces,
+ const std::shared_ptr<GeomAlgoAPI_MakeShape>& theMakeShape,
+ const std::shared_ptr<GeomAPI_DataMapOfShapeShape>& theDataMap);
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: FeaturesPlugin_ExtrusionSketch.cpp
+// Created: 11 September 2015
+// Author: Dmitry Bobylev
+
+#include <FeaturesPlugin_ExtrusionSketch.h>
+
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
+
+#include <GeomAlgoAPI_Prism.h>
+
+//=================================================================================================
+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<GeomAPI_Shape> theFace,
+ std::shared_ptr<GeomAPI_Shape>& theResult,
+ ListOfShape& theFromFaces,
+ ListOfShape& theToFaces,
+ std::shared_ptr<GeomAlgoAPI_MakeShape>& theMakeShape,
+ std::shared_ptr<GeomAPI_DataMapOfShapeShape>& 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<GeomAPI_Shape> aToShape;
+ std::shared_ptr<GeomAPI_Shape> aFromShape;
+
+ if(string(CREATION_METHOD())->value() == "ByPlanesAndOffsets") {
+ std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = selection(TO_OBJECT_ID());
+ if(anObjRef.get() != NULL) {
+ aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(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<GeomAPI_Shape>(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();
+}
--- /dev/null
+// 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 <FeaturesPlugin_CompositeSketch.h>
+
+/** \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<GeomAPI_Shape> theFace,
+ std::shared_ptr<GeomAPI_Shape>& theResult,
+ ListOfShape& theFromFaces,
+ ListOfShape& theToFaces,
+ std::shared_ptr<GeomAlgoAPI_MakeShape>& theMakeShape,
+ std::shared_ptr<GeomAPI_DataMapOfShapeShape>& theDataMap);
+
+public:
+ /// Use plugin manager for features creation.
+ FeaturesPlugin_ExtrusionSketch();
+};
+
+#endif
#include <FeaturesPlugin_Boolean.h>
#include <FeaturesPlugin_Extrusion.h>
+#include <FeaturesPlugin_ExtrusionSketch.h>
#include <FeaturesPlugin_ExtrusionCut.h>
#include <FeaturesPlugin_ExtrusionFuse.h>
#include <FeaturesPlugin_Group.h>
#include <FeaturesPlugin_Partition.h>
#include <FeaturesPlugin_Placement.h>
#include <FeaturesPlugin_Revolution.h>
+#include <FeaturesPlugin_RevolutionSketch.h>
#include <FeaturesPlugin_RevolutionCut.h>
#include <FeaturesPlugin_RevolutionFuse.h>
#include <FeaturesPlugin_Rotation.h>
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();
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: FeaturesPlugin_RevolutionSketch.cpp
+// Created: 11 September 2015
+// Author: Dmitry Bobylev
+
+#include <FeaturesPlugin_RevolutionSketch.h>
+
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
+
+#include <GeomAlgoAPI_Revolution.h>
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Lin.h>
+
+//=================================================================================================
+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<GeomAPI_Shape> theFace,
+ std::shared_ptr<GeomAPI_Shape>& theResult,
+ ListOfShape& theFromFaces,
+ ListOfShape& theToFaces,
+ std::shared_ptr<GeomAlgoAPI_MakeShape>& theMakeShape,
+ std::shared_ptr<GeomAPI_DataMapOfShapeShape>& theDataMap)
+{
+ //Getting axis.
+ std::shared_ptr<GeomAPI_Ax1> anAxis;
+ std::shared_ptr<GeomAPI_Edge> anEdge;
+ std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = selection(FeaturesPlugin_RevolutionSketch::AXIS_OBJECT_ID());
+ if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) {
+ anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->value()));
+ } else if(anObjRef->context() && anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) {
+ anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->context()->shape()));
+ }
+ if(anEdge) {
+ anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(), anEdge->line()->direction()));
+ }
+
+ // 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<GeomAPI_Shape> aToShape;
+ std::shared_ptr<GeomAPI_Shape> aFromShape;
+
+ if(string(CREATION_METHOD())->value() == "ByPlanesAndOffsets") {
+ anObjRef = selection(TO_OBJECT_ID());
+ if(anObjRef.get() != NULL) {
+ aToShape = std::dynamic_pointer_cast<GeomAPI_Shape>(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<GeomAPI_Shape>(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();
+}
--- /dev/null
+// 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 <FeaturesPlugin_CompositeSketch.h>
+
+/** \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<GeomAPI_Shape> theFace,
+ std::shared_ptr<GeomAPI_Shape>& theResult,
+ ListOfShape& theFromFaces,
+ ListOfShape& theToFaces,
+ std::shared_ptr<GeomAlgoAPI_MakeShape>& theMakeShape,
+ std::shared_ptr<GeomAPI_DataMapOfShapeShape>& theDataMap);
+
+public:
+ /// Use plugin manager for features creation.
+ FeaturesPlugin_RevolutionSketch();
+};
+
+#endif
--- /dev/null
+<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+<source>
+ <groupbox title="Extrusion">
+ <sketch_launcher id="sketch"
+ label="Sketch"
+ icon=":icons/sketch.png"
+ use_body="false"
+ tooltip="Create or edit a sketch">
+ </sketch_launcher>
+ <toolbox id="CreationMethod">
+ <box id="BySizes" title="By sizes" icon=":icons/dimension_up_down_32x32.png">
+ <groupbox>
+ <doublevalue
+ id="from_size"
+ label="Size"
+ step="1.0"
+ default="10"
+ icon=":icons/dimension_down.png"
+ tooltip="From size">
+ </doublevalue>
+ </groupbox>
+ <groupbox>
+ <doublevalue
+ id="to_size"
+ label="Size"
+ step="1.0"
+ default="0"
+ icon=":icons/dimension_up.png"
+ tooltip="To size">
+ </doublevalue>
+ </groupbox>
+ </box>
+ <box id="ByPlanesAndOffsets" title="By bounding planes and offsets" icon=":icons/plane_inverted_32x32.png">
+ <groupbox title="From">
+ <shape_selector id="from_object"
+ icon=":icons/plane.png"
+ label="Plane face"
+ tooltip="Bounding plane (select a planar face)"
+ shape_types="face"
+ default="<base sketch>">
+ <validator id="GeomValidators_Face" parameters="plane"/>
+ </shape_selector>
+ <doublevalue id="from_offset"
+ label="Offset" step="1.0" default="0"
+ icon=":icons/dimension_up_down.png"
+ tooltip="Offset for bounding plane">
+ </doublevalue>
+ </groupbox>
+ <groupbox title="To">
+ <shape_selector id="to_object"
+ icon=":icons/plane_inverted.png"
+ label="Plane face"
+ tooltip="Bounding plane (select a planar face)"
+ shape_types="face"
+ default="<base sketch>">
+ <validator id="GeomValidators_Face" parameters="plane"/>
+ </shape_selector>
+ <doublevalue id="to_offset"
+ label="Offset" step="1.0" default="0"
+ icon=":icons/dimension_up_down.png"
+ tooltip="Offset for bounding plane">
+ </doublevalue>
+ </groupbox>
+ </box>
+ </toolbox>
+ </groupbox>
+ <validator id="GeomValidators_ZeroOffset" parameters="CreationMethod,BySizes,to_size,from_size,to_object,to_offset,from_object,from_offset"/>
+</source>
<feature id="Extrusion" title="Extrusion" tooltip="Create a solid by extrusion of a face" icon=":icons/extrusion.png">
<source path="extrusion_widget.xml"/>
</feature>
+ <feature id="ExtrusionSketch" title="ExtrusionSketch" tooltip="Create a solids by extrusion of a sketch" icon=":icons/extrusionsketch.png">
+ <source path="extrusionsketch_widget.xml"/>
+ </feature>
<feature id="ExtrusionCut" title="ExtrusionCut" tooltip="" icon=":icons/extrusion_cut.png">
<source path="extrusioncut_widget.xml"/>
</feature>
<feature id="Revolution" title="Revolution" tooltip="Create a solid by revolution of a face" icon=":icons/revol.png">
<source path="revolution_widget.xml"/>
</feature>
+ <feature id="RevolutionSketch" title="RevolutionSketch" tooltip="Create a solids by revolution of a sketch" icon=":icons/revolsketch.png">
+ <source path="revolutionsketch_widget.xml"/>
+ </feature>
<feature id="RevolutionCut" title="RevolutionCut" tooltip="" icon=":icons/revol_cut.png">
<source path="revolutioncut_widget.xml"/>
</feature>
--- /dev/null
+<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+<source>
+ <groupbox title="Revolution">
+ <sketch_launcher id="sketch"
+ label="Sketch"
+ icon=":icons/sketch.png"
+ use_body="false"
+ tooltip="Create or edit a sketch">
+ </sketch_launcher>
+ <toolbox id="CreationMethod">
+ <box id="ByAngles" title="By angles" icon=":icons/angle_up_down_32x32.png">
+ <shape_selector id="axis_object"
+ icon=":icons/axis.png"
+ label="Axis"
+ tooltip="Select an edge for axis"
+ shape_types="edge"
+ default="">
+ <validator id="GeomValidators_ShapeType" parameters="line"/>
+ </shape_selector>
+ <groupbox>
+ <doublevalue
+ id="from_angle"
+ label="Angle"
+ step="1.0"
+ default="10"
+ icon=":icons/angle_down.png"
+ tooltip="From angle">
+ </doublevalue>
+ </groupbox>
+ <groupbox>
+ <doublevalue
+ id="to_angle"
+ label="Angle"
+ step="1.0"
+ default="0"
+ icon=":icons/angle_up.png"
+ tooltip="To angle">
+ </doublevalue>
+ </groupbox>
+ </box>
+ <box id="ByPlanesAndOffsets" title="By bounding planes and offsets" icon=":icons/plane_inverted_32x32.png">
+ <shape_selector id="axis_object"
+ icon=":icons/axis.png"
+ label="Axis"
+ tooltip="Select an edge for axis"
+ shape_types="edge"
+ default="">
+ <validator id="GeomValidators_ShapeType" parameters="line"/>
+ </shape_selector>
+ <groupbox title="From">
+ <shape_selector id="from_object"
+ icon=":icons/plane.png"
+ label="Plane face"
+ tooltip="Bounding plane (select a planar face)"
+ shape_types="face"
+ default="<sketch>">
+ <validator id="GeomValidators_Face" parameters="plane"/>
+ </shape_selector>
+ <doublevalue id="from_offset" label="Offset"
+ step="1.0" default="0"
+ icon=":icons/angle_up_down.png"
+ tooltip="Offset for bounding plane">
+ </doublevalue>
+ </groupbox>
+ <groupbox title="To">
+ <shape_selector id="to_object"
+ icon=":icons/plane_inverted.png"
+ label="Plane face"
+ tooltip="Bounding plane (select a planar face)"
+ shape_types="face"
+ default="<sketch>">
+ <validator id="GeomValidators_Face" parameters="plane"/>
+ </shape_selector>
+ <doublevalue id="to_offset" label="Offset"
+ step="1.0" default="0"
+ icon=":icons/angle_up_down.png"
+ tooltip="Offset for bounding plane">
+ </doublevalue>
+ </groupbox>
+ </box>
+ </toolbox>
+ </groupbox>
+ <validator id="GeomValidators_ZeroOffset" parameters="CreationMethod,ByAngles,to_angle,from_angle,to_object,to_offset,from_object,from_offset"/>
+</source>
#include "PartSet_WidgetSketchCreator.h"
#include "PartSet_Module.h"
+#include <Config_Keywords.h>
+
#include <XGUI_ModuleConnector.h>
#include <XGUI_Workshop.h>
#include <XGUI_Displayer.h>
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);
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);
}
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<ModelAPI_ResultBody>(aObj);
- if (aBody.get() != NULL) {
- aHasBody = true;
- break;
+ if(!aHasBody) {
+ foreach(ObjectPtr aObj, aObjList) {
+ aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObj);
+ if (aBody.get() != NULL) {
+ aHasBody = true;
+ break;
+ }
}
}
}
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<ModelAPI_AttributeSelection>
- (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<ModelAPI_AttributeSelection>
+ (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();
+ }
}
}
}
/// 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
<file>icons/duplicate.png</file>
<file>icons/remove.png</file>
<file>icons/extrusion.png</file>
+ <file>icons/extrusionsketch.png</file>
<file>icons/cut.png</file>
<file>icons/cut_tool.png</file>
<file>icons/cut_shape.png</file>
<file>icons/fusion.png</file>
<file>icons/revol.png</file>
+ <file>icons/revolsketch.png</file>
<file>icons/revol_cut.png</file>
<file>icons/revol_fuse.png</file>
<file>icons/common.png</file>