#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeDouble.h>
#include <GeomAPI_Edge.h>
+#include <GeomAPI_Vertex.h>
#include <GeomAlgoAPI_EdgeBuilder.h>
#include <GeomAlgoAPI_PointBuilder.h>
ModelAPI_AttributeSelection::typeId());
data()->addAttribute(ConstructionPlugin_Axis::CYLINDRICAL_FACE(),
ModelAPI_AttributeSelection::typeId());
+ data()->addAttribute(ConstructionPlugin_Axis::X_DIRECTION(),
+ ModelAPI_AttributeDouble::typeId());
+ data()->addAttribute(ConstructionPlugin_Axis::Y_DIRECTION(),
+ ModelAPI_AttributeDouble::typeId());
+ data()->addAttribute(ConstructionPlugin_Axis::Z_DIRECTION(),
+ ModelAPI_AttributeDouble::typeId());
}
void ConstructionPlugin_Axis::createAxisByTwoPoints()
}
}
+
+void ConstructionPlugin_Axis::createAxisByPointAndDirection()
+{
+ AttributeSelectionPtr aRef1 = data()->selection(ConstructionPlugin_Axis::POINT_FIRST());
+ AttributeDoublePtr aXAttr = data()->real(ConstructionPlugin_Axis::X_DIRECTION());
+ AttributeDoublePtr aYAttr = data()->real(ConstructionPlugin_Axis::Y_DIRECTION());
+ AttributeDoublePtr aZAttr = data()->real(ConstructionPlugin_Axis::Z_DIRECTION());
+ if ((aRef1.get() != NULL) && (aXAttr.get() != NULL) &&
+ (aYAttr.get() != NULL) && (aZAttr.get() != NULL)) {
+ GeomShapePtr aShape1 = aRef1->value();
+ if (!aShape1.get())
+ aShape1 = aRef1->context()->shape();
+
+ std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aXAttr->value(),
+ aYAttr->value(),
+ aZAttr->value()));
+ if (aShape1->isVertex() && (!aShape1->isEqual(aVertex))) {
+ std::shared_ptr<GeomAPI_Pnt> aStart = GeomAlgoAPI_PointBuilder::point(aShape1);
+ std::shared_ptr<GeomAPI_Pnt> anEnd = GeomAlgoAPI_PointBuilder::point(aVertex);
+ if (aStart->distance(anEnd) > ConstructionPlugin_Axis::MINIMAL_LENGTH()) {
+ std::shared_ptr<GeomAPI_Edge> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
+
+ ResultConstructionPtr aConstr = document()->createConstruction(data());
+ aConstr->setInfinite(true);
+ aConstr->setShape(anEdge);
+ setResult(aConstr);
+ }
+ }
+ }
+}
+
+
void ConstructionPlugin_Axis::createAxisByCylindricalFace()
{
std::shared_ptr<GeomAPI_Shape> aSelection = data()->selection(CYLINDRICAL_FACE())->value();
}
}
+
+
void ConstructionPlugin_Axis::execute()
{
AttributeStringPtr aMethodTypeAttr = string(ConstructionPlugin_Axis::METHOD());
createAxisByTwoPoints();
} else if (aMethodType == "AxisByCylindricalFaceCase") {
createAxisByCylindricalFace();
+ } else if (aMethodType == "AxisByPointAndDirection") {
+ createAxisByPointAndDirection();
}
}
return CYLINDRICAL_FACE_ATTR;
}
+ /// attribute name for X direction
+ inline static const std::string& X_DIRECTION()
+ {
+ static const std::string ATTR_X_DIRECTION("X_Direction");
+ return ATTR_X_DIRECTION;
+ }
+
+ /// attribute name for Y direction
+ inline static const std::string& Y_DIRECTION()
+ {
+ static const std::string ATTR_Y_DIRECTION("Y_Direction");
+ return ATTR_Y_DIRECTION;
+ }
+
+ /// attribute name for Y direction
+ inline static const std::string& Z_DIRECTION()
+ {
+ static const std::string ATTR_Z_DIRECTION("Z_Direction");
+ return ATTR_Z_DIRECTION;
+ }
+
/// Returns a minimal length for axis
inline static const double MINIMAL_LENGTH() { return 1.e-5; }
void createAxisByTwoPoints();
/// Creates a new axis as copy of cylindrical face axis
void createAxisByCylindricalFace();
+ /// Creates a new axis by point and direction
+ void createAxisByPointAndDirection();
};
#include <TopoDS.hxx>
#include <TopoDS_Vertex.hxx>
#include <BRep_Tool.hxx>
+#include <BRep_Builder.hxx>
#include <gp_Pnt.hxx>
#include <Precision.hxx>
}
}
+GeomAPI_Vertex::GeomAPI_Vertex(double theX, double theY, double theZ)
+{
+ TopoDS_Vertex aVertex;
+ BRep_Builder aBuilder;
+ aBuilder.MakeVertex(aVertex, gp_Pnt(theX, theY, theZ), Precision::Confusion());
+ setImpl(new TopoDS_Shape(aVertex));
+}
+
std::shared_ptr<GeomAPI_Pnt> GeomAPI_Vertex::point()
{
const TopoDS_Shape& aShape = const_cast<GeomAPI_Vertex*>(this)->impl<TopoDS_Shape>();
GEOMAPI_EXPORT
GeomAPI_Vertex();
- /// Creation of edge by the edge-shape
+ /// Creation of vertex by the vertex-shape
GEOMAPI_EXPORT
GeomAPI_Vertex(const std::shared_ptr<GeomAPI_Shape>& theShape);
+ /// Creation of vertex by 3d coordinates
+ GEOMAPI_EXPORT
+ GeomAPI_Vertex(double theX, double theY, double theZ);
+
/// Returns the first vertex coordinates of the edge
GEOMAPI_EXPORT
std::shared_ptr<GeomAPI_Pnt> point();
#include <ModelAPI_Document.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_Events.h>
#include <ModelAPI_Result.h>
new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)));
Events_Loop::loop()->send(aMsg);
- aFeatures.push_back(createPoint(aDoc));
+ FeaturePtr aOrigin = createPoint(aDoc, "Origin", 0., 0., 0.);
+ aFeatures.push_back(aOrigin);
+ aFeatures.push_back(createAxis(aDoc, aOrigin, 100., 0., 0.));
+ aFeatures.push_back(createAxis(aDoc, aOrigin, 0., 100., 0.));
+ aFeatures.push_back(createAxis(aDoc, aOrigin, 0., 0., 100.));
aFeatures.push_back(createPlane(aDoc, 1., 0., 0.));
aFeatures.push_back(createPlane(aDoc, 0., -1., 0.));
aFeatures.push_back(createPlane(aDoc, 0., 0., 1.));
return aPlane;
}
-FeaturePtr InitializationPlugin_Plugin::createPoint(DocumentPtr theDoc)
+FeaturePtr InitializationPlugin_Plugin::createPoint(DocumentPtr theDoc, const std::string& theName,
+ double theX, double theY, double theZ)
{
std::shared_ptr<ModelAPI_Feature> aPoint = theDoc->addFeature("Point");
- aPoint->real("x")->setValue(0.);
- aPoint->real("y")->setValue(0.);
- aPoint->real("z")->setValue(0.);
- aPoint->data()->setName("Origin");
+ aPoint->real("x")->setValue(theX);
+ aPoint->real("y")->setValue(theY);
+ aPoint->real("z")->setValue(theZ);
+ aPoint->data()->setName(theName);
aPoint->setInHistory(aPoint, false); // don't show automatically created feature in the features history
// the point should be executed in order to build the feature result immediatelly
return aPoint;
}
+
+FeaturePtr InitializationPlugin_Plugin::createAxis(DocumentPtr theDoc, FeaturePtr theOrigin,
+ double theX, double theY, double theZ)
+{
+ std::shared_ptr<ModelAPI_Feature> aAxis = theDoc->addFeature("Axis");
+ aAxis->string("CreationMethod")->setValue("AxisByPointAndDirection");
+
+ ResultPtr aResult = theOrigin->firstResult();
+ aAxis->selection("FirstPoint")->setValue(aResult, aResult->shape());
+
+ aAxis->real("X_Direction")->setValue(theX);
+ aAxis->real("Y_Direction")->setValue(theY);
+ aAxis->real("Z_Direction")->setValue(theZ);
+
+ if (theX != 0) {
+ aAxis->data()->setName("OX");
+ } else if (theY != 0) {
+ aAxis->data()->setName("OY");
+ } else if (theZ != 0) {
+ aAxis->data()->setName("OZ");
+ }
+ aAxis->setInHistory(aAxis, false); // don't show automatically created feature in the features history
+ aAxis->execute();
+ aAxis->data()->execState(ModelAPI_StateDone);
+ aAxis->firstResult()->data()->execState(ModelAPI_StateDone);
+
+ return aAxis;
+}
FeaturePtr createPlane(DocumentPtr theDoc, double theX, double theY, double theZ);
/// Creates the origin point in (0,0,0)
/// \param theDoc - document to contain a "point" feature
- FeaturePtr createPoint(DocumentPtr theDoc);
+ /// \param theName - name of the point
+ /// \param theX - X coordinate
+ /// \param theY - Y coordinate
+ /// \param theZ - Z coordinate
+ FeaturePtr createPoint(DocumentPtr theDoc, const std::string& theName,
+ double theX, double theY, double theZ);
+
+ /// Creates an axis which is started from origin point
+ /// \param theDoc - document to contain an "axis" feature
+ /// \param theOrigin - origin point feature
+ /// \param theX - X of direction point
+ /// \param theY - Y of direction point
+ /// \param theZ - Z of direction point
+ FeaturePtr createAxis(DocumentPtr theDoc, FeaturePtr theOrigin,
+ double theX, double theY, double theZ);
};
#endif
void ParametersPlugin_WidgetParamsMgr::activateCustom()
{
+ updateParametersFeatures();
+ updateParametersPart();
+ updateFeaturesPart();
+
+ myFeatures->setExpanded(true);
+ myParameters->setExpanded(true);
+}
+
+void ParametersPlugin_WidgetParamsMgr::updateParametersFeatures()
+{
+ myParametersList.clear();
FeaturePtr aFeature = feature();
DocumentPtr aDoc = aFeature->document();
int aNbParam = aDoc->size(ModelAPI_ResultParameter::group());
myParametersList.append(aParamFeature);
}
}
- updateParametersPart();
- updateFeaturesPart();
-
- myFeatures->setExpanded(true);
- myParameters->setExpanded(true);
}
void ParametersPlugin_WidgetParamsMgr::updateFeaturesPart()
Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED));
Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ updateParametersFeatures();
updateFeaturesPart();
+ updateParametersPart();
}
}
myParameters->insertChild(aCurrentPos - 1, aCurrentItem);
selectItemScroll(aCurrentItem);
+
+ //Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED));
+ //Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED));
+ //Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ //updateParametersFeatures();
+ //updateParametersPart();
+ //updateFeaturesPart();
}
void ParametersPlugin_WidgetParamsMgr::onDown()
myParameters->insertChild(aCurrentPos + 1, aCurrentItem);
selectItemScroll(aCurrentItem);
+
+ //Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED));
+ //Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED));
+ //Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ //updateParametersFeatures();
+ //updateParametersPart();
+ //updateFeaturesPart();
}
QList<QStringList> featuresItems(const QList<FeaturePtr>& theFeatures) const;
QList<QStringList> parametersItems(const QList<FeaturePtr>& theFeatures) const;
+ void updateParametersFeatures();
+
QTreeWidget* myTable;
QTreeWidgetItem* myFeatures;
QTreeWidgetItem* myParameters;
#include <ModelAPI_Feature.h>
#include <ModelAPI_Tools.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_ResultConstruction.h>
#include <AIS_InteractiveContext.hxx>
#include <AIS_Axis.hxx>
#ifdef DEBUG_DELIVERY
// Fill by trihedron shapes
Handle(AIS_Axis) aAxis = Handle(AIS_Axis)::DownCast(anIO);
+ DocumentPtr aDoc = ModelAPI_Session::get()->moduleDocument();
+ int aSize = aDoc->size(ModelAPI_ResultConstruction::group());
+ ObjectPtr aObj;
if (!aAxis.IsNull()) {
// an Axis from Trihedron
- Handle(Geom_Line) aLine = aAxis->Component();
- Handle(Prs3d_DatumAspect) DA = aAxis->Attributes()->DatumAspect();
- Handle(Geom_TrimmedCurve) aTLine = new Geom_TrimmedCurve(aLine, 0, DA->FirstAxisLength());
-
- BRep_Builder aBuilder;
- TopoDS_Edge aEdge;
- aBuilder.MakeEdge(aEdge, aTLine, Precision::Confusion());
- if (!aEdge.IsNull()) {
- std::shared_ptr<GeomAPI_Shape> aGeomShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
- aGeomShape->setImpl(new TopoDS_Shape(aEdge));
- thePrs->setShape(aGeomShape);
+ gp_Lin aLine = aAxis->Component()->Lin();
+ gp_Dir aDir = aLine.Direction();
+ std::string aAxName;
+ if (aDir.X() == 1.)
+ aAxName = "OX";
+ else if (aDir.Y() == 1.)
+ aAxName = "OY";
+ else if (aDir.Z() == 1.)
+ aAxName = "OZ";
+ if (aAxName.length() > 0) {
+ ResultPtr aAx;
+ for (int i = 0; i < aSize; i++) {
+ aObj = aDoc->object(ModelAPI_ResultConstruction::group(), i);
+ if (aObj->data()->name() == aAxName) {
+ aAx = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aObj);
+ break;
+ }
+ }
+ if (aAx.get()) {
+ thePrs->setObject(aAx);
+ thePrs->setShape(aAx->shape());
+ }
}
} else {
Handle(AIS_Point) aPoint = Handle(AIS_Point)::DownCast(anIO);
if (!aPoint.IsNull()) {
- // A point from trihedron
- Handle(Geom_Point) aPnt = aPoint->Component();
- BRep_Builder aBuilder;
- TopoDS_Vertex aVertex;
- aBuilder.MakeVertex(aVertex, aPnt->Pnt(), Precision::Confusion());
- if (!aVertex.IsNull()) {
- std::shared_ptr<GeomAPI_Shape> aGeomShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
- aGeomShape->setImpl(new TopoDS_Shape(aVertex));
- thePrs->setShape(aGeomShape);
+ // An origin point from trihedron
+ ResultPtr aOrigin;
+ for (int i = 0; i < aSize; i++) {
+ aObj = aDoc->object(ModelAPI_ResultConstruction::group(), i);
+ if (aObj->data()->name() == "Origin") {
+ aOrigin = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aObj);
+ break;
+ }
+ }
+ if (aOrigin.get()) {
+ thePrs->setObject(aOrigin);
+ thePrs->setShape(aOrigin->shape());
}
}
}