#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
+#include <BuildPlugin_Vertex.h>
#include <BuildPlugin_Wire.h>
#include <BuildPlugin_Validators.h>
// Register validators.
SessionPtr aMgr = ModelAPI_Session::get();
ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+ aFactory->registerValidator("BuildPlugin_ValidatorBaseForVertex",
+ new BuildPlugin_ValidatorBaseForVertex());
aFactory->registerValidator("BuildPlugin_ValidatorBaseForWire",
new BuildPlugin_ValidatorBaseForWire());
//=================================================================================================
FeaturePtr BuildPlugin_Plugin::createFeature(std::string theFeatureID)
{
- if (theFeatureID == BuildPlugin_Wire::ID()) {
+ if(theFeatureID == BuildPlugin_Vertex::ID()) {
+ return FeaturePtr(new BuildPlugin_Vertex());
+ } else if(theFeatureID == BuildPlugin_Wire::ID()) {
return FeaturePtr(new BuildPlugin_Wire());
}
#include <Events_Error.h>
+//=================================================================================================
+bool BuildPlugin_ValidatorBaseForVertex::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ std::string& theError) const
+{
+ // Get base objects list.
+ if(theAttribute->attributeType() != ModelAPI_AttributeSelectionList::typeId()) {
+ Events_Error::send("Validator does not support attribute type \"" + theAttribute->attributeType()
+ + "\"\n Only \"" + ModelAPI_AttributeSelectionList::typeId() + "\" supported.");
+ return false;
+ }
+ AttributeSelectionListPtr aSelectionList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+ if(!aSelectionList.get()) {
+ theError = "Could not get selection list.";
+ return false;
+ }
+ if(aSelectionList->size() == 0) {
+ theError = "Empty selection list.";
+ return false;
+ }
+
+ // Collect base shapes.
+ for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+ AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
+ if(!aSelection.get()) {
+ theError = "Could not get selection.";
+ return false;
+ }
+ ResultPtr aContext = aSelection->context();
+ if(!aContext.get()) {
+ theError = "Attribute have empty context.";
+ return false;
+ }
+
+ GeomShapePtr aShape = aSelection->value();
+ GeomShapePtr aContextShape = aContext->shape();
+ if(!aShape.get()) {
+ aShape = aContextShape;
+ }
+ if(!aShape.get()) {
+ theError = "Empty shape selected.";
+ return false;
+ }
+
+ // Check that shape has acceptable type.
+ if(aShape->shapeType() != GeomAPI_Shape::VERTEX) {
+ theError = "Selected shape has wrong type. Only vertices acceptable.";
+ return false;
+ }
+
+ // Check that it is vertex on sketch.
+ ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
+ if(aConstruction.get()) {
+ if(aConstruction->isInfinite()) {
+ theError = "Inifinte objects not acceptable.";
+ return false;
+ }
+
+ std::shared_ptr<GeomAPI_PlanarEdges> anEdges = std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aContextShape);
+ if(!anEdges.get()) {
+ // It is not an edge on the sketch.
+ // Check that it is not local selection.
+ if(!aShape->isEqual(aContextShape)) {
+ // Local selection on body does not allowed.
+ theError = "Selected shape is in the local selection. Only global selection is allowed.";
+ return false;
+ }
+ }
+ }
+ }
+
+ return true;
+}
+
//=================================================================================================
bool BuildPlugin_ValidatorBaseForWire::isValid(const AttributePtr& theAttribute,
const std::list<std::string>& theArguments,
}
return true;
-}
\ No newline at end of file
+}
#include <ModelAPI_AttributeValidator.h>
#include <ModelAPI_FeatureValidator.h>
+/// \class BuildPlugin_ValidatorBaseForVertex
+/// \ingroup Validators
+/// \brief A validator for selection base shapes for vertex. Allows to select vertices on sketch and
+/// vertex objects.
+class BuildPlugin_ValidatorBaseForVertex: public ModelAPI_AttributeValidator
+{
+public:
+ //! Returns true if attribute is ok.
+ //! \param[in] theAttribute the checked attribute.
+ //! \param[in] theArguments arguments of the attribute.
+ //! \param[out] theError error message.
+ virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ std::string& theError) const;
+};
+
/// \class BuildPlugin_ValidatorBaseForWire
/// \ingroup Validators
/// \brief A validator for selection base shapes for wire. Allows to select edges on sketch and
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: BuildPlugin_Vertex.cpp
+// Created: 18 April 2016
+// Author: Dmitry Bobylev
+
+#include "BuildPlugin_Vertex.h"
+
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultConstruction.h>
+
+#include <Events_Error.h>
+
+#include <GeomAPI_DataMapOfShapeShape.h>
+#include <GeomAPI_PlanarEdges.h>
+#include <GeomAPI_ShapeExplorer.h>
+
+#include <GeomAlgoAPI_ShapeTools.h>
+#include <GeomAlgoAPI_WireBuilder.h>
+
+#include <algorithm>
+
+//=================================================================================================
+BuildPlugin_Vertex::BuildPlugin_Vertex()
+{
+}
+
+//=================================================================================================
+void BuildPlugin_Vertex::initAttributes()
+{
+ data()->addAttribute(BASE_OBJECTS_ID(), ModelAPI_AttributeSelectionList::typeId());
+}
+
+//=================================================================================================
+void BuildPlugin_Vertex::execute()
+{
+ // Get base objects list.
+ AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID());
+ if(!aSelectionList.get()) {
+ setError("Error: Could not get selection list.");
+ return;
+ }
+ if(aSelectionList->size() == 0) {
+ setError("Error: Empty selection list.");
+ return;
+ }
+
+ // Collect base shapes.
+ ListOfShape aListOfShapes;
+ int aResultIndex = 0;
+ for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+ AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
+ GeomShapePtr aShape = aSelection->value();
+ if(!aShape.get()) {
+ ResultPtr aContext = aSelection->context();
+ if(!aContext.get()) {
+ setError("Error: Attribute has empty context.");
+ return;
+ }
+
+ aShape = aContext->shape();
+ }
+ if(!aShape.get()) {
+ setError("Error: Empty shape selected.");
+ return;
+ }
+
+ if(aShape->shapeType() != GeomAPI_Shape::VERTEX) {
+ setError("Error: Selected shape has wrong type. Only vertices acceptable.");
+ return;
+ }
+
+ // Store result.
+ ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
+ aResultBody->store(aShape);
+ setResult(aResultBody, aResultIndex);
+ ++aResultIndex;
+ }
+
+ removeResults(aResultIndex);
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: BuildPlugin_Vertex.h
+// Created: 18 April 2016
+// Author: Dmitry Bobylev
+
+#ifndef BuildPlugin_Vertex_H_
+#define BuildPlugin_Vertex_H_
+
+#include "BuildPlugin.h"
+
+#include <ModelAPI_Feature.h>
+
+/// \class BuildPlugin_Vertex
+/// \ingroup Plugins
+/// \brief Feature for creation of vertex from sketch vertex or existing vertices.
+class BuildPlugin_Vertex: public ModelAPI_Feature
+{
+public:
+ /// Use plugin manager for features creation
+ BuildPlugin_Vertex();
+
+ /// Feature kind.
+ inline static const std::string& ID()
+ {
+ static const std::string MY_ID("Vertex");
+ return MY_ID;
+ }
+
+ /// Attribute name of base objects.
+ inline static const std::string& BASE_OBJECTS_ID()
+ {
+ static const std::string MY_BASE_OBJECTS_ID("base_objects");
+ return MY_BASE_OBJECTS_ID;
+ }
+
+ /// \return the kind of a feature.
+ BUILDPLUGIN_EXPORT virtual const std::string& getKind()
+ {
+ static std::string MY_KIND = BuildPlugin_Vertex::ID();
+ return MY_KIND;
+ }
+
+ /// Request for initialization of data model of the feature: adding all attributes.
+ BUILDPLUGIN_EXPORT virtual void initAttributes();
+
+ /// Creates a new part document if needed.
+ BUILDPLUGIN_EXPORT virtual void execute();
+};
+
+#endif
SET(PROJECT_HEADERS
BuildPlugin.h
BuildPlugin_Plugin.h
+ BuildPlugin_Vertex.h
BuildPlugin_Wire.h
BuildPlugin_Validators.h
)
SET(PROJECT_SOURCES
BuildPlugin_Plugin.cpp
+ BuildPlugin_Vertex.cpp
BuildPlugin_Wire.cpp
BuildPlugin_Validators.cpp
)
SET(XML_RESOURCES
plugin-Build.xml
+ vertex_widget.xml
wire_widget.xml
)
<plugin>
<workbench id="Build" document="Part">
<group id="Shape">
+ <feature id="Vertex" title="Vertex" tooltip ="Create a vertex from sketch vertex and vertex objects" icon="icons/Build/feature_vertex.png">
+ <source path="vertex_widget.xml"/>
+ </feature>
<feature id="Wire" title="Wire" tooltip ="Create a wire from sketch edges and wires objects" icon="icons/Build/feature_wire.png">
<source path="wire_widget.xml"/>
</feature>
--- /dev/null
+<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+<source>
+ <multi_selector id="base_objects"
+ label="Vertices:"
+ tooltip="Select a vertices on sketch or vertex objects."
+ type_choice="vertex objects">
+ <validator id="BuildPlugin_ValidatorBaseForVertex"/>
+ </multi_selector>
+</source>
return true;
}
}
+
+ return false;
}
if(!aShape->isEqual(aContextShape)) {