#include "SketchPlugin_ConstraintCollinear.h"
+#include "SketcherPrs_Factory.h"
+
SketchPlugin_ConstraintCollinear::SketchPlugin_ConstraintCollinear()
{
}
if (!sketch())
return thePrevious;
- AISObjectPtr anAIS;
- // TODO
- //AISObjectPtr anAIS = SketcherPrs_Factory::collinearConstraint(this, sketch()->coordinatePlane(),
- // thePrevious);
+ AISObjectPtr anAIS = SketcherPrs_Factory::collinearConstraint(this, sketch()->coordinatePlane(),
+ thePrevious);
return anAIS;
}
#include "SketchPlugin_ConstraintMiddle.h"
+#include "SketcherPrs_Factory.h"
+
SketchPlugin_ConstraintMiddle::SketchPlugin_ConstraintMiddle()
{
}
if (!sketch())
return thePrevious;
- AISObjectPtr anAIS;
- // TODO
- //AISObjectPtr anAIS = SketcherPrs_Factory::collinearConstraint(this, sketch()->coordinatePlane(),
- // thePrevious);
+ AISObjectPtr anAIS = SketcherPrs_Factory::middleConstraint(this, sketch()->coordinatePlane(),
+ thePrevious);
return anAIS;
}
/** \class SketchPlugin_ConstraintMiddle
* \ingroup Plugins
- * \brief Feature for creation of a new constraintwhich places a point in the middle of a line
+ * \brief Feature for creation of a new constraint which places a point in the middle of a line
*
* This constraint has two attributes:
* SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B()
SET(PROJECT_PICTURES
+ icons/collinear.png
icons/parallel.png
icons/perpendicular.png
icons/anchor.png
icons/vertical.png
icons/equal.png
icons/tangent.png
+ icons/middlepoint.png
icons/mirror.png
icons/rotate.png
icons/translate.png
Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
aGroup->SetPrimitivesAspect(aLineAspect);
- // Draw first line
- ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
- std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getShape(aObj);
- if (aLine.get() == NULL)
- return;
- drawShape(aLine, thePrs);
-
- // Draw second line
- aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
- aLine = SketcherPrs_Tools::getShape(aObj);
- if (aLine.get() == NULL)
- return;
- drawShape(aLine, thePrs);
+ // Draw constrained lines
+ addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
+ addLine(aGroup, SketchPlugin_Constraint::ENTITY_B());
}
// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
// File: SketcherPrs_Collinear.h
-// Created: 29 February 2016
+// Created: 29 Feb 2016
// Author: Natalia ERMOLAEVA
#ifndef SketcherPrs_Collinear_H
const std::shared_ptr<GeomAPI_Ax3>& thePlane);
protected:
- virtual const char* iconName() const { return "equal.png"; }
+ virtual const char* iconName() const { return "collinear.png"; }
virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const;
#include "SketcherPrs_Factory.h"
#include "SketcherPrs_Coincident.h"
+#include "SketcherPrs_Collinear.h"
#include "SketcherPrs_Parallel.h"
#include "SketcherPrs_Perpendicular.h"
#include "SketcherPrs_Rigid.h"
#include "SketcherPrs_Tangent.h"
#include "SketcherPrs_Radius.h"
#include "SketcherPrs_LengthDimension.h"
+#include "SketcherPrs_Middle.h"
#include "SketcherPrs_Mirror.h"
#include "SketcherPrs_Transformation.h"
#include "SketcherPrs_Angle.h"
}
CONSTRAINT_PRS_IMPL(coincidentConstraint, SketcherPrs_Coincident);
+CONSTRAINT_PRS_IMPL(collinearConstraint, SketcherPrs_Collinear);
CONSTRAINT_PRS_IMPL(parallelConstraint, SketcherPrs_Parallel);
CONSTRAINT_PRS_IMPL(perpendicularConstraint, SketcherPrs_Perpendicular);
CONSTRAINT_PRS_IMPL(rigidConstraint, SketcherPrs_Rigid);
CONSTRAINT_PRS_IMPL(tangentConstraint, SketcherPrs_Tangent);
CONSTRAINT_PRS_IMPL(radiusConstraint, SketcherPrs_Radius);
CONSTRAINT_PRS_IMPL(lengthDimensionConstraint, SketcherPrs_LengthDimension);
+CONSTRAINT_PRS_IMPL(middleConstraint, SketcherPrs_Middle);
CONSTRAINT_PRS_IMPL(mirrorConstraint, SketcherPrs_Mirror);
CONSTRAINT_PRS_IMPL(angleConstraint, SketcherPrs_Angle);
/// \param thePlane the current sketch plane
GET_CONSTRAINT_PRS(coincidentConstraint)
+ /// Creates collinear constraint presentation
+ /// \param theConstraint the constraint
+ /// \param thePlane the current sketch plane
+ GET_CONSTRAINT_PRS(collinearConstraint)
+
/// Creates parallel constraint presentation
/// \param theConstraint the constraint
/// \param thePlane the current sketch plane
/// \param thePlane the current sketch plane
GET_CONSTRAINT_PRS(lengthDimensionConstraint)
+ /// Creates middle constraint presentation
+ /// \param theConstraint the constraint
+ /// \param thePlane the current sketch plane
+ GET_CONSTRAINT_PRS(middleConstraint)
+
/// Creates mirror constraint presentation
/// \param theConstraint the constraint
/// \param thePlane the current sketch plane
{
myPntArray = new Graphic3d_ArrayOfPoints(2);
myPntArray->AddVertex(0., 0., 0.);
- myPntArray->AddVertex(0., 0., 0.);
}
bool SketcherPrs_Middle::IsReadyToDisplay(ModelAPI_Feature* theConstraint,
ObjectPtr aObj1 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_A());
ObjectPtr aObj2 = SketcherPrs_Tools::getResult(theConstraint, SketchPlugin_Constraint::ENTITY_B());
- aReadyToDisplay = SketcherPrs_Tools::getShape(aObj1).get() != NULL &&
- SketcherPrs_Tools::getShape(aObj2).get() != NULL;
+ // one object is a feature Line, other object is a point result. We check shape of point result
+ aReadyToDisplay = aObj1.get() && aObj2.get() &&
+ (SketcherPrs_Tools::getShape(aObj1).get() != NULL ||
+ SketcherPrs_Tools::getShape(aObj2).get() != NULL);
return aReadyToDisplay;
}
{
if (!IsReadyToDisplay(myConstraint, myPlane))
return false;
-
- ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
- ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
+ ObjectPtr aPointObject;
+
+ // find a line result to set middle symbol near it
+ AttributePtr anAttribute = SketcherPrs_Tools::getAttribute(myConstraint, SketchPlugin_Constraint::ENTITY_A());
+ if (!anAttribute.get()) {
+ ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
+ std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(aObj);
+ if (aShape.get() && aShape->isEdge())
+ aPointObject = aObj;
+ }
+ if (!aPointObject.get()) {
+ ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
+ std::shared_ptr<GeomAPI_Shape> aShape = SketcherPrs_Tools::getShape(aObj);
+ if (aShape.get() && aShape->isEdge())
+ aPointObject = aObj;
+ }
+
+ if (!aPointObject.get())
+ return false;
// Set points of the presentation
SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
- gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep);
- gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep);
+ gp_Pnt aP1 = aMgr->getPosition(aPointObject, this, theStep);
myPntArray->SetVertice(1, aP1);
- myPntArray->SetVertice(2, aP2);
return true;
}
Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
aGroup->SetPrimitivesAspect(aLineAspect);
- // Draw first line
- ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
- std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getShape(aObj);
- if (aLine.get() == NULL)
- return;
- drawShape(aLine, thePrs);
-
- // Draw second line
- aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B());
- aLine = SketcherPrs_Tools::getShape(aObj);
- if (aLine.get() == NULL)
- return;
- drawShape(aLine, thePrs);
+ // Draw objects
+ ObjectPtr aObject = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
+ drawLine(thePrs, theColor, aObject);
+
+ aObject = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A());
+ drawLine(thePrs, theColor, aObject);
+}
+
+void SketcherPrs_Middle::drawLine(const Handle(Prs3d_Presentation)& thePrs,
+ Quantity_Color theColor, const ObjectPtr& theObject) const
+{
+ FeaturePtr aLineFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
+ if (aLineFeature.get()) {
+ std::list<ResultPtr> aResults = aLineFeature->results();
+ if (aResults.size() == 1) {
+ ResultPtr aResult = aResults.front();
+ std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getShape(aResult);
+ if (aLine.get() != NULL)
+ drawShape(aLine, thePrs);
+ }
+ }
+ else {
+ std::shared_ptr<GeomAPI_Shape> aLine = SketcherPrs_Tools::getShape(theObject);
+ if (aLine.get() != NULL)
+ drawShape(aLine, thePrs);
+ }
}
const std::shared_ptr<GeomAPI_Ax3>& thePlane);
protected:
- virtual const char* iconName() const { return "equal.png"; }
+ virtual const char* iconName() const { return "middlepoint.png"; }
virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const;
/// Update myPntArray according to presentation positions
/// \return true in case of success
virtual bool updatePoints(double theStep) const;
+
+ /// Draw shape of the object. Find shape result if the object is feature
+ void drawLine(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor,
+ const ObjectPtr& theObject) const;
};
#endif
\ No newline at end of file
namespace SketcherPrs_Tools {
+AttributePtr getAttribute(ModelAPI_Feature* theFeature, const std::string& theAttrName)
+{
+ std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = aData->refattr(theAttrName);
+ return !anAttr->isObject() ? anAttr->attr() : AttributePtr();
+}
+
ObjectPtr getResult(ModelAPI_Feature* theFeature, const std::string& theAttrName)
{
std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
#include <GeomAPI_Pnt2d.h>
#include <GeomAPI_Ax3.h>
#include <ModelAPI_Object.h>
+#include <ModelAPI_Attribute.h>
#include <ModelAPI_Feature.h>
#include <string>
Sel_Dimension_Text
};
+ /// Returns attribute object referenced by feature
+ /// \param theFeature a feature
+ /// \param theAttrName an attribute name
+ SKETCHERPRS_EXPORT AttributePtr getAttribute(ModelAPI_Feature* theFeature,
+ const std::string& theAttrName);
+
/// Returns result object referenced by feature
/// \param theFeature a feature
/// \param theAttrName an attribute name