ConstructionPlugin.h
ConstructionPlugin_Plugin.h
ConstructionPlugin_Point.h
+ ConstructionPlugin_Axis.h
)
SET(PROJECT_SOURCES
ConstructionPlugin_Plugin.cpp
ConstructionPlugin_Point.cpp
+ ConstructionPlugin_Axis.cpp
)
SET(XML_RESOURCES
plugin-Construction.xml
point_widget.xml
+ axis_widget.xml
)
SET(PROJECT_LIBRARIES
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ConstructionPlugin_Axis.cpp
+// Created: 12 Dec 2014
+// Author: Vitaly Smetannikov
+
+#include "ConstructionPlugin_Axis.h"
+
+#include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_ResultConstruction.h>
+
+#include <GeomAPI_Edge.h>
+#include <GeomAlgoAPI_EdgeBuilder.h>
+#include <GeomAlgoAPI_PointBuilder.h>
+
+using namespace std;
+
+static const double MINIMAL_LENGTH = 1.e-5;
+
+ConstructionPlugin_Axis::ConstructionPlugin_Axis()
+{
+}
+
+void ConstructionPlugin_Axis::initAttributes()
+{
+ data()->addAttribute(POINT_ATTR_FIRST, ModelAPI_AttributeReference::type());
+ data()->addAttribute(POINT_ATTR_SECOND, ModelAPI_AttributeReference::type());
+}
+
+void ConstructionPlugin_Axis::execute()
+{
+ AttributeReferencePtr aRef1 = data()->reference(POINT_ATTR_FIRST);
+ AttributeReferencePtr aRef2 = data()->reference(POINT_ATTR_SECOND);
+ if ((aRef1.get() != NULL) && (aRef2.get() != NULL)) {
+ ResultConstructionPtr aPntObj1 = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aRef1->value());
+ ResultConstructionPtr aPntObj2 = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aRef2->value());
+ if ((aPntObj1.get() != NULL) && (aPntObj2.get() != NULL)) {
+ GeomShapePtr aShape1 = aPntObj1->shape();
+ GeomShapePtr aShape2 = aPntObj2->shape();
+ if (aShape1->isVertex() && aShape2->isVertex()) {
+ std::shared_ptr<GeomAPI_Pnt> aStart = GeomAlgoAPI_PointBuilder::point(aShape1);
+ std::shared_ptr<GeomAPI_Pnt> anEnd = GeomAlgoAPI_PointBuilder::point(aShape2);
+ if (aStart->distance(anEnd) > MINIMAL_LENGTH) {
+ std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
+
+ ResultConstructionPtr aConstr = document()->createConstruction(data());
+ aConstr->setShape(anEdge);
+ setResult(aConstr);
+ }
+ }
+ }
+ }
+}
+
+void ConstructionPlugin_Axis::customisePresentation(AISObjectPtr thePrs)
+{
+ thePrs->setColor(0, 0, 0);
+ thePrs->setLineStyle(3);
+}
\ No newline at end of file
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ConstructionPlugin_Axis.h
+// Created: 12 Dec 2014
+// Author: Vitaly Smetannikov
+
+#ifndef ConstructionPlugin_Axis_H
+#define ConstructionPlugin_Axis_H
+
+#include "ConstructionPlugin.h"
+#include <ModelAPI_Feature.h>
+#include <GeomAPI_ICustomPrs.h>
+
+
+/// Point kind
+const std::string CONSTRUCTION_AXIS_KIND("Axis");
+
+/// attribute name for first point
+const std::string POINT_ATTR_FIRST = "firstPoint";
+
+/// attribute name for second point
+const std::string POINT_ATTR_SECOND = "secondPoint";
+
+/**\class ConstructionPlugin_Axis
+ * \ingroup DataModel
+ * \brief Feature for creation of the new axis in PartSet.
+ */
+class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomPrs
+{
+ public:
+ /// Returns the kind of a feature
+ CONSTRUCTIONPLUGIN_EXPORT virtual const std::string& getKind()
+ {
+ static std::string MY_KIND = CONSTRUCTION_AXIS_KIND;
+ return MY_KIND;
+ }
+
+ /// Creates a new part document if needed
+ CONSTRUCTIONPLUGIN_EXPORT virtual void execute();
+
+ /// Request for initialization of data model of the feature: adding all attributes
+ CONSTRUCTIONPLUGIN_EXPORT virtual void initAttributes();
+
+ /// Construction result is allways recomuted on the fly
+ CONSTRUCTIONPLUGIN_EXPORT virtual bool isPersistentResult() {return false;}
+
+ /// Use plugin manager for features creation
+ ConstructionPlugin_Axis();
+
+ /// Customize presentation of the feature
+ virtual void customisePresentation(AISObjectPtr thePrs);
+};
+
+
+#endif
\ No newline at end of file
#include "ConstructionPlugin_Plugin.h"
#include "ConstructionPlugin_Point.h"
+#include "ConstructionPlugin_Axis.h"
#include <ModelAPI_Session.h>
#include <ModelAPI_Document.h>
if (theFeatureID == CONSTRUCTION_POINT_KIND) {
return FeaturePtr(new ConstructionPlugin_Point);
}
+ else if (theFeatureID == CONSTRUCTION_AXIS_KIND) {
+ return FeaturePtr(new ConstructionPlugin_Axis);
+ }
// feature of such kind is not found
return FeaturePtr();
}
return MY_KIND;
}
- /// Returns to which group in the document must be added feature
- CONSTRUCTIONPLUGIN_EXPORT virtual const std::string& getGroup()
- {
- static std::string MY_GROUP = "Construction";
- return MY_GROUP;
- }
-
/// Creates a new part document if needed
CONSTRUCTIONPLUGIN_EXPORT virtual void execute();
--- /dev/null
+<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+<source>
+ <shape_selector id="firstPoint"
+ label="First point"
+ icon=":icons/point.png"
+ tooltip="Select a first point for the axis"
+ shape_types="vertex"
+ />
+ <shape_selector id="secondPoint"
+ label="Second point"
+ icon=":icons/point.png"
+ tooltip="Select a second point for the axis"
+ shape_types="vertex">
+ <validator id="PartSet_DifferentObjects"/>
+ </shape_selector>
+</source>
id="Axis"
title="Axis"
tooltip="Create a new axis"
- icon=":icons/axis.png"
- keysequence=""
- internal="true" />
+ icon=":icons/axis.png">
+ <source path="axis_widget.xml" />
+ </feature>
<feature
id="Plane"
title="Plane"
}
}
}
+
+
+void GeomAPI_AISObject::setLineStyle(int theStyle)
+{
+ Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+ if (!anAIS.IsNull()) {
+ Handle(AIS_Drawer) aDrawer = anAIS->Attributes();
+ if (aDrawer->HasLineAspect())
+ aDrawer->LineAspect()->SetTypeOfLine((Aspect_TypeOfLine)theStyle);
+ if (aDrawer->HasWireAspect())
+ aDrawer->WireAspect()->SetTypeOfLine((Aspect_TypeOfLine)theStyle);
+ //else {
+ // Quantity_NameOfColor aCol = Quantity_NOC_RED;
+ // aDrawer->SetLineAspect(new Prs3d_LineAspect(aCol, (Aspect_TypeOfLine)theStyle, 1));
+ //}
+ }
+}
/// Sets marker type for vertex.
/// The type has to be defined according to Acpect_TypeOfMarker
void setPointMarker(int theType, double theScale);
+
+ /// Set line type of edges
+ /// Has to be defined according to Aspect_TypeOfLine
+ void setLineStyle(int theStyle);
};
//! Pointer on attribute object
#include <GeomAPI_Pnt.h>
#include <GeomAPI_Shape.h>
#include <BRepBuilderAPI_MakeVertex.hxx>
+#include <BRep_Tool.hxx>
#include <TopoDS_Vertex.hxx>
+#include <TopoDS.hxx>
+#include <gp_Pnt.hxx>
std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_PointBuilder::point(
std::shared_ptr<GeomAPI_Pnt> thePoint)
aRes->setImpl(new TopoDS_Shape(aVertex));
return aRes;
}
+
+
+std::shared_ptr<GeomAPI_Pnt> GeomAlgoAPI_PointBuilder::point(std::shared_ptr<GeomAPI_Shape> theVertex)
+{
+ TopoDS_Shape aShape = theVertex->impl<TopoDS_Shape>();
+ if ((!aShape.IsNull()) && (aShape.ShapeType() == TopAbs_VERTEX)) {
+ TopoDS_Vertex aVertex = TopoDS::Vertex(aShape);
+ gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
+ std::shared_ptr<GeomAPI_Pnt> aPnt(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
+ return aPnt;
+ }
+ return std::shared_ptr<GeomAPI_Pnt>();
+}
class GEOMALGOAPI_EXPORT GeomAlgoAPI_PointBuilder
{
public:
- /// Creates linear edge by two points
+ /// Creates a shape by point
static std::shared_ptr<GeomAPI_Shape> point(std::shared_ptr<GeomAPI_Pnt> thePoint);
+
+ /// Return point by shape vertex
+ static std::shared_ptr<GeomAPI_Pnt> point(std::shared_ptr<GeomAPI_Shape> theVertex);
};
#endif
void PartSet_Module::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
{
ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
- if (aOperation->isEditOperation()) {
+ if (aOperation && aOperation->isEditOperation()) {
std::string aId = aOperation->id().toStdString();
if ((aId == SketchPlugin_ConstraintLength::ID()) ||
(aId == SketchPlugin_ConstraintDistance::ID()) ||
GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(theObject);
bool isShading = false;
- if (aPrs) {
+ if (aPrs.get() != NULL) {
anAIS = aPrs->getAISObject(AISObjectPtr());
} else {
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
- if (aResult) {
+ if (aResult.get() != NULL) {
std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
- if (aShapePtr) {
+ if (aShapePtr.get() != NULL) {
anAIS = AISObjectPtr(new GeomAPI_AISObject());
anAIS->setImpl(new Handle(AIS_InteractiveObject)(new ModuleBase_ResultPrs(aResult)));
//anAIS->createShape(aShapePtr);