#include "SketchPlugin_ConstraintRigid.h"
#include "SketchPlugin_ConstraintParallel.h"
+#include <SketcherPrs_Factory.h>
+
#include <ModelAPI_ResultConstruction.h>
#include <Config_PropManager.h>
if (!sketch())
return thePrevious;
- std::shared_ptr<ModelAPI_Data> aData = data();
- std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
- ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
- if (!anAttr /*|| !anAttr->isObject()*/)
- return thePrevious;
-
- std::shared_ptr<GeomAPI_Shape> aShape;
-
- if (anAttr->isObject()) {
- std::shared_ptr<ModelAPI_ResultConstruction> aConst;
- aConst = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(anAttr->object());
-
- if (!aConst)
- return thePrevious;
-
- std::shared_ptr<SketchPlugin_Feature> aSketchFea =
- std::dynamic_pointer_cast<SketchPlugin_Feature>(ModelAPI_Feature::feature(aConst));
- if (aSketchFea.get() != NULL) {
- if (aSketchFea->isExternal())
- return thePrevious;
- }
- aShape = aConst->shape();
- }
- else {
- std::shared_ptr<GeomDataAPI_Point2D> aPointAttr =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
- if (!aPointAttr)
- return thePrevious;
- std::shared_ptr<GeomAPI_Pnt> aPoint(sketch()->to3D(aPointAttr->x(), aPointAttr->y()));
- aShape = GeomAlgoAPI_PointBuilder::point(aPoint);
- }
-
AISObjectPtr anAIS = thePrevious;
- if (!anAIS)
- anAIS = AISObjectPtr(new GeomAPI_AISObject);
-
- std::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
- anAIS->createFixed(aShape, aPlane);
-
- // Set color from preferences
- std::vector<int> aRGB = Config_PropManager::color("Visualization", "sketch_constraint_color",
- SKETCH_CONSTRAINT_COLOR);
-
- anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
+ if (!anAIS) {
+ anAIS = SketcherPrs_Factory::rigidConstraint(this, sketch()->coordinatePlane());
+ }
return anAIS;
}
\ No newline at end of file
SketcherPrs_Perpendicular.h
SketcherPrs_SymbolPrs.h
SketcherPrs_PositionMgr.h
+ SketcherPrs_Rigid.h
)
SET(PROJECT_SOURCES
SketcherPrs_Perpendicular.cpp
SketcherPrs_SymbolPrs.cpp
SketcherPrs_PositionMgr.cpp
+ SketcherPrs_Rigid.cpp
)
SET(PROJECT_LIBRARIES
SET(PROJECT_PICTURES
icons/parallel.png
icons/perpendicular.png
+ icons/anchor.png
)
ADD_DEFINITIONS(-DCONSTRAINTS_EXPORTS ${CAS_DEFINITIONS})
#include <SketcherPrs_Coincident.h>
#include <SketcherPrs_Parallel.h>
#include <SketcherPrs_Perpendicular.h>
+#include <SketcherPrs_Rigid.h>
AISObjectPtr SketcherPrs_Factory::coincidentConstraint(SketchPlugin_Constraint* theConstraint,
aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs));
return aAISObj;
}
+
+AISObjectPtr SketcherPrs_Factory::rigidConstraint(SketchPlugin_Constraint* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane)
+{
+ std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
+ Handle(SketcherPrs_Rigid) aPrs = new SketcherPrs_Rigid(theConstraint, thePlane);
+ aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aPrs));
+ return aAISObj;
+}
/// \param thePlane the current sketch plane
static AISObjectPtr perpendicularConstraint(SketchPlugin_Constraint* theConstraint,
const std::shared_ptr<GeomAPI_Ax3>& thePlane);
+
+ /// Creates coincedent perpendicular presentation
+ /// \param theConstraint the constraint
+ /// \param thePlane the current sketch plane
+ static AISObjectPtr rigidConstraint(SketchPlugin_Constraint* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane);
};
#endif
aGroup->AddPrimitiveArray(myPntArray);
}
-void SketcherPrs_Parallel::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
- const Standard_Integer aMode)
-{
- ClearSelected();
-
- Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this);
- Handle(Select3D_SensitivePoint) aSP1 = new Select3D_SensitivePoint(aOwn, myPntArray->Vertice(1));
- Handle(Select3D_SensitivePoint) aSP2 = new Select3D_SensitivePoint(aOwn, myPntArray->Vertice(2));
- aSelection->Add(aSP1);
- aSelection->Add(aSP2);
-}
-
-void SketcherPrs_Parallel::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
- const SelectMgr_SequenceOfOwner& theOwners)
-{
-
- Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
- aSelectionPrs->Clear();
- drawLines(aSelectionPrs, Quantity_NOC_WHITE);
-
- aSelectionPrs->SetDisplayPriority(9);
- aSelectionPrs->Display();
- thePM->Highlight(this);
-}
-
-void SketcherPrs_Parallel::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM,
- const Quantity_NameOfColor theColor, const Handle(SelectMgr_EntityOwner)& theOwner)
-{
- thePM->Color(this, theColor);
-
- Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
- aHilightPrs->Clear();
- drawLines(aHilightPrs, theColor);
-
- if (thePM->IsImmediateModeOn())
- thePM->AddToImmediateList(aHilightPrs);
-}
-
-
void SketcherPrs_Parallel::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
{
Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
/// \param thePlane a coordinate plane of current sketch
Standard_EXPORT SketcherPrs_Parallel(SketchPlugin_Constraint* theConstraint,
const std::shared_ptr<GeomAPI_Ax3>& thePlane);
-
- //! Method which draws selected owners ( for fast presentation draw )
- Standard_EXPORT virtual void HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
- const SelectMgr_SequenceOfOwner& theOwners);
-
- //! Method which hilight an owner belonging to
- //! this selectable object ( for fast presentation draw )
- Standard_EXPORT virtual void HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM,
- const Quantity_NameOfColor theColor, const Handle(SelectMgr_EntityOwner)& theOwner);
-
DEFINE_STANDARD_RTTI(SketcherPrs_Parallel)
protected:
/// Redefinition of virtual function
Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
- /// Redefinition of virtual function
- Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
- const Standard_Integer aMode) ;
-
virtual const char* iconName() const { return "parallel.png"; }
-private:
-
- void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const;
-
- Handle(Graphic3d_ArrayOfPoints) myPntArray;
+ virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const;
};
#endif
\ No newline at end of file
#include <Graphic3d_AspectLine3d.hxx>
#include <Graphic3d_ArrayOfSegments.hxx>
-#include <Select3D_SensitivePoint.hxx>
-#include <Select3D_SensitiveSegment.hxx>
-
-#include <SelectMgr_SequenceOfOwner.hxx>
-#include <SelectMgr_Selection.hxx>
-#include <SelectMgr_EntityOwner.hxx>
-
// Function which is defined in SketchPlugin_ConstraintDistance.cpp
extern std::shared_ptr<GeomAPI_Pnt2d> getFeaturePoint(DataPtr theData,
SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
gp_Pnt aP1 = aMgr->getPosition(aLine1, this);
gp_Pnt aP2 = aMgr->getPosition(aLine2, this);
- //std::shared_ptr<GeomAPI_Pnt> aPnt1 = aLine1->firstPoint();
- //std::shared_ptr<GeomAPI_Pnt> aPnt2 = aLine1->lastPoint();
- //gp_Pnt aP1((aPnt1->x() + aPnt2->x())/2.,
- // (aPnt1->y() + aPnt2->y())/2.,
- // (aPnt1->z() + aPnt2->z())/2.);
-
- //gp_Vec aVec1(aPnt1->impl<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
- //gp_Vec aShift = aVec1.Crossed(myPlane->norm()->impl<gp_Dir>());
- //aShift.Normalize();
- //aShift.Multiply(20);
- //aP1.Translate(aShift);
-
- //aPnt1 = aLine2->firstPoint();
- //aPnt2 = aLine2->lastPoint();
- //gp_Pnt aP2((aPnt1->x() + aPnt2->x())/2.,
- // (aPnt1->y() + aPnt2->y())/2.,
- // (aPnt1->z() + aPnt2->z())/2.);
-
- //gp_Vec aVec2(aPnt1->impl<gp_Pnt>(), aPnt2->impl<gp_Pnt>());
- //aShift = aVec2.Crossed(myPlane->norm()->impl<gp_Dir>());
- //aShift.Normalize();
- //aShift.Multiply(20);
- //aP2.Translate(aShift);
Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
aGroup->SetPrimitivesAspect(myAspect);
aGroup->AddPrimitiveArray(myPntArray);
}
-void SketcherPrs_Perpendicular::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
- const Standard_Integer aMode)
-{
- ClearSelected();
-
- Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this);
- Handle(Select3D_SensitivePoint) aSP1 = new Select3D_SensitivePoint(aOwn, myPntArray->Vertice(1));
- Handle(Select3D_SensitivePoint) aSP2 = new Select3D_SensitivePoint(aOwn, myPntArray->Vertice(2));
- aSelection->Add(aSP1);
- aSelection->Add(aSP2);
-}
-
-void SketcherPrs_Perpendicular::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
- const SelectMgr_SequenceOfOwner& theOwners)
-{
-
- Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
- aSelectionPrs->Clear();
- drawLines(aSelectionPrs, Quantity_NOC_WHITE);
-
- aSelectionPrs->SetDisplayPriority(9);
- aSelectionPrs->Display();
- thePM->Highlight(this);
-}
-
-void SketcherPrs_Perpendicular::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM,
- const Quantity_NameOfColor theColor, const Handle(SelectMgr_EntityOwner)& theOwner)
-{
- thePM->Color(this, theColor);
-
- Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
- aHilightPrs->Clear();
- drawLines(aHilightPrs, theColor);
-
- if (thePM->IsImmediateModeOn())
- thePM->AddToImmediateList(aHilightPrs);
-}
-
-
void SketcherPrs_Perpendicular::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
{
Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
Standard_EXPORT SketcherPrs_Perpendicular(SketchPlugin_Constraint* theConstraint,
const std::shared_ptr<GeomAPI_Ax3>& thePlane);
- //! Method which draws selected owners ( for fast presentation draw )
- Standard_EXPORT virtual void HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
- const SelectMgr_SequenceOfOwner& theOwners);
-
- //! Method which hilight an owner belonging to
- //! this selectable object ( for fast presentation draw )
- Standard_EXPORT virtual void HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM,
- const Quantity_NameOfColor theColor, const Handle(SelectMgr_EntityOwner)& theOwner);
-
-
DEFINE_STANDARD_RTTI(SketcherPrs_Perpendicular)
protected:
/// Redefinition of virtual function
Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
- /// Redefinition of virtual function
- Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
- const Standard_Integer aMode) ;
-
virtual const char* iconName() const { return "perpendicular.png"; }
-private:
-
- void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const;
-
- Handle(Graphic3d_ArrayOfPoints) myPntArray;
+ /// Redefine this function in order to add additiona lines of constraint base
+ /// \param thePrs a presentation
+ /// \param theColor a color of additiona lines
+ virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const;
};
#endif
\ No newline at end of file
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: SketcherPrs_Rigid.cpp
+// Created: 16 February 2015
+// Author: Vitaly SMETANNIKOV
+
+#include "SketcherPrs_Rigid.h"
+#include "SketcherPrs_Tools.h"
+#include "SketcherPrs_PositionMgr.h"
+
+#include <GeomAPI_Pnt.h>
+
+#include <SketchPlugin_Constraint.h>
+
+#include <AIS_Drawer.hxx>
+#include <gp_Pnt2d.hxx>
+
+#include <Prs3d_PointAspect.hxx>
+#include <Prs3d_Root.hxx>
+#include <Prs3d_LineAspect.hxx>
+
+#include <Graphic3d_MarkerImage.hxx>
+#include <Graphic3d_AspectMarker3d.hxx>
+#include <Graphic3d_AspectLine3d.hxx>
+#include <Graphic3d_ArrayOfSegments.hxx>
+
+#include <Select3D_SensitivePoint.hxx>
+#include <Select3D_SensitiveSegment.hxx>
+
+#include <SelectMgr_SequenceOfOwner.hxx>
+#include <SelectMgr_Selection.hxx>
+#include <SelectMgr_EntityOwner.hxx>
+
+
+extern std::shared_ptr<GeomAPI_Pnt2d> getFeaturePoint(DataPtr theData,
+ const std::string& theAttribute);
+
+
+IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Rigid, SketcherPrs_SymbolPrs);
+IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Rigid, SketcherPrs_SymbolPrs);
+
+static Handle(Image_AlienPixMap) MyPixMap;
+
+SketcherPrs_Rigid::SketcherPrs_Rigid(SketchPlugin_Constraint* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane)
+ : SketcherPrs_SymbolPrs(theConstraint, thePlane)
+{
+ myPntArray = new Graphic3d_ArrayOfPoints(1);
+ myPntArray->AddVertex(0., 0., 0.);
+}
+
+void SketcherPrs_Rigid::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+ const Handle(Prs3d_Presentation)& thePresentation,
+ const Standard_Integer theMode)
+{
+ prepareAspect();
+
+ std::shared_ptr<GeomAPI_Shape> aLine1 = SketcherPrs_Tools::getLine(myConstraint, SketchPlugin_Constraint::ENTITY_A());
+ if (aLine1.get() == NULL)
+ return;
+
+ SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
+ gp_Pnt aP1 = aMgr->getPosition(aLine1, this);
+
+ Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
+ aGroup->SetPrimitivesAspect(myAspect);
+ myPntArray->SetVertice(1, aP1);
+ aGroup->AddPrimitiveArray(myPntArray);
+}
+
+void SketcherPrs_Rigid::drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const
+{
+ Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(thePrs);
+
+ Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(theColor, Aspect_TOL_SOLID, 2);
+ aGroup->SetPrimitivesAspect(aLineAspect);
+
+ addLine(aGroup, SketchPlugin_Constraint::ENTITY_A());
+}
+
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: SketcherPrs_Rigid.h
+// Created: 16 February 2015
+// Author: Vitaly SMETANNIKOV
+
+#ifndef SketcherPrs_Rigid_H
+#define SketcherPrs_Rigid_H
+
+#include "SketcherPrs_SymbolPrs.h"
+
+class SketchPlugin_Constraint;
+class SketchPlugin_Sketch;
+
+
+DEFINE_STANDARD_HANDLE(SketcherPrs_Rigid, SketcherPrs_SymbolPrs)
+
+/**
+* \ingroup GUI
+* A redefinition of standard AIS Interactive Object in order to provide
+* presentation of parallel constraint
+*/
+class SketcherPrs_Rigid: public SketcherPrs_SymbolPrs
+{
+public:
+ /// Constructor
+ /// \param theConstraint a constraint feature
+ /// \param thePlane a coordinate plane of current sketch
+ Standard_EXPORT SketcherPrs_Rigid(SketchPlugin_Constraint* theConstraint,
+ const std::shared_ptr<GeomAPI_Ax3>& thePlane);
+
+ DEFINE_STANDARD_RTTI(SketcherPrs_Rigid)
+protected:
+ /// Redefinition of virtual function
+ Standard_EXPORT virtual void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+ const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0);
+
+ virtual const char* iconName() const { return "anchor.png"; }
+
+ /// Redefine this function in order to add additiona lines of constraint base
+ /// \param thePrs a presentation
+ /// \param theColor a color of additiona lines
+ virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const;
+};
+
+#endif
\ No newline at end of file
#include <Graphic3d_ArrayOfSegments.hxx>
+#include <SelectMgr_Selection.hxx>
+#include <SelectMgr_EntityOwner.hxx>
+#include <Select3D_SensitivePoint.hxx>
+
#ifdef WIN32
# define FSEP "\\"
aLines->AddVertex(aPnt2->impl<gp_Pnt>());
theGroup->AddPrimitiveArray(aLines);
}
+
+void SketcherPrs_SymbolPrs::HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
+ const SelectMgr_SequenceOfOwner& theOwners)
+{
+
+ Handle( Prs3d_Presentation ) aSelectionPrs = GetSelectPresentation( thePM );
+ aSelectionPrs->Clear();
+ drawLines(aSelectionPrs, Quantity_NOC_WHITE);
+
+ aSelectionPrs->SetDisplayPriority(9);
+ aSelectionPrs->Display();
+ thePM->Highlight(this);
+}
+
+void SketcherPrs_SymbolPrs::HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM,
+ const Quantity_NameOfColor theColor, const Handle(SelectMgr_EntityOwner)& theOwner)
+{
+ thePM->Color(this, theColor);
+
+ Handle( Prs3d_Presentation ) aHilightPrs = GetHilightPresentation( thePM );
+ aHilightPrs->Clear();
+ drawLines(aHilightPrs, theColor);
+
+ if (thePM->IsImmediateModeOn())
+ thePM->AddToImmediateList(aHilightPrs);
+}
+
+
+
+void SketcherPrs_SymbolPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
+ const Standard_Integer aMode)
+{
+ ClearSelected();
+
+ if (!myPntArray.IsNull()) {
+ Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this);
+ for (int i = 1; i <= myPntArray->VertexNumber(); i++) {
+ Handle(Select3D_SensitivePoint) aSP = new Select3D_SensitivePoint(aOwn, myPntArray->Vertice(i));
+ aSelection->Add(aSP);
+ }
+ }
+}
//! to this selectable object ( for fast presentation draw )
Standard_EXPORT virtual void ClearSelected();
+
+ //! Method which draws selected owners ( for fast presentation draw )
+ Standard_EXPORT virtual void HilightSelected(const Handle(PrsMgr_PresentationManager3d)& thePM,
+ const SelectMgr_SequenceOfOwner& theOwners);
+
+ //! Method which hilight an owner belonging to
+ //! this selectable object ( for fast presentation draw )
+ Standard_EXPORT virtual void HilightOwnerWithColor(const Handle(PrsMgr_PresentationManager3d)& thePM,
+ const Quantity_NameOfColor theColor, const Handle(SelectMgr_EntityOwner)& theOwner);
+
Standard_EXPORT std::shared_ptr<GeomAPI_Ax3> plane() const { return myPlane; }
Standard_EXPORT SketchPlugin_Constraint* feature() const { return myConstraint; }
DEFINE_STANDARD_RTTI(SketcherPrs_SymbolPrs)
protected:
+
+ /// Redefinition of virtual function
+ Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
+ const Standard_Integer aMode);
+
/// Returns an icon file name. Has to be redefined in successors
virtual const char* iconName() const = 0;
/// \param theAttrName an attribute name which corresponds to referenced line
void addLine(const Handle(Graphic3d_Group)& theGroup, std::string theAttrName) const;
+ /// Redefine this function in order to add additiona lines of constraint base
+ /// \param thePrs a presentation
+ /// \param theColor a color of additiona lines
+ virtual void drawLines(const Handle(Prs3d_Presentation)& thePrs, Quantity_Color theColor) const {}
+
protected:
/// Constraint feature
SketchPlugin_Constraint* myConstraint;
/// Aspect for entities drawing
Handle(Graphic3d_AspectMarker3d) myAspect;
+ /// Array of symbols positions
+ Handle(Graphic3d_ArrayOfPoints) myPntArray;
+
private:
/// Static map to collect constraints icons {IconName : IconPixMap}
static std::map<const char*, Handle(Image_AlienPixMap)> myIconsMap;
+
};
#endif
\ No newline at end of file