PartSet_OperationSketchBase.h
PartSet_OperationSketch.h
PartSet_OperationSketchLine.h
+ PartSet_Presentation.h
PartSet_TestOCC.h
PartSet_Tools.h
)
PartSet_OperationSketchBase.cpp
PartSet_OperationSketch.cpp
PartSet_OperationSketchLine.cpp
+ PartSet_Presentation.cpp
PartSet_TestOCC.cpp
PartSet_Tools.cpp
)
#include <ModuleBase_OperationDescription.h>
#include <PartSet_Listener.h>
#include <PartSet_TestOCC.h>
+#include <PartSet_Presentation.h>
#include <ModuleBase_Operation.h>
#include <ModelAPI_Object.h>
#include <GeomAPI_Shape.h>
#include <AIS_ListOfInteractive.hxx>
+#include <AIS_DimensionSelectionMode.hxx>
#include <QObject>
#include <QMouseEvent>
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
if (isDisplay) {
boost::shared_ptr<GeomAPI_Shape> aPreview = aPreviewOp->preview(theFeature);
- bool isAISCreated = aDisplayer->Redisplay(theFeature, aPreview ?
- aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), false);
- if (isAISCreated) {
- PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
- if (aSketchOp) {
- Handle(AIS_InteractiveObject) anAIS = aDisplayer->GetAISObject(theFeature);
- aSketchOp->correctPresentation(anAIS);
- }
+ Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation(
+ theFeature, aPreviewOp->sketch(),
+ aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(),
+ aDisplayer->GetAISObject(theFeature));
+
+ int aSelectionMode = -1;
+ if (theFeature->getKind() == "SketchConstraintLength") {
+ aSelectionMode = AIS_DSM_Text;
}
+ aDisplayer->Redisplay(theFeature, anAIS, aSelectionMode, false);
}
else
aDisplayer->Erase(theFeature, false);
for (; anIt != aLast; anIt++) {
boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).first;
boost::shared_ptr<GeomAPI_Shape> aPreview = (*anIt).second;
- aDisplayer->Redisplay(aFeature,
- aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), false);
+ Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation(
+ aFeature, aPreviewOp->sketch(),
+ aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(),
+ aDisplayer->GetAISObject(aFeature));
+ if (!anAIS.IsNull())
+ aDisplayer->Redisplay(aFeature, anAIS, -1, false);
aDisplayer->ActivateInLocalContext(aFeature, aModes, false);
}
aDisplayer->UpdateViewer();
#include <ModelAPI_Document.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_AttributeDouble.h>
#include <SketchPlugin_Constraint.h>
bool isFoundPoint = false;
gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
+*/
if (theSelected.empty()) {
- PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY);
- isFoundPoint = true;
+ //PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY);
+ //isFoundPoint = true;
}
else {
XGUI_ViewerPrs aPrs = theSelected.front();
- const TopoDS_Shape& aShape = aPrs.shape();
+ boost::shared_ptr<ModelAPI_Feature> aFeature = aPrs.feature();
+
+ setFeature(aFeature);
+ setValue(120);
+ flushUpdated();
+
+ /*const TopoDS_Shape& aShape = aPrs.shape();
if (!aShape.IsNull()) // the point is selected
{
if (aShape.ShapeType() == TopAbs_VERTEX) {
isFoundPoint = true;
}
}
- }
+ }*/
}
- switch (myPointSelectionMode)
+ /*switch (myPointSelectionMode)
{
case SM_FirstPoint: {
setLinePoint(feature(), aX, anY, LINE_ATTR_START);
break;
default:
break;
- }
-*/
+ }*/
}
void PartSet_OperationConstraint::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
flushCreated();
return aNewFeature;
}
+
+void PartSet_OperationConstraint::setFeature(boost::shared_ptr<ModelAPI_Feature> theFeature)
+{
+ if (!theFeature || theFeature->getKind() != "SketchLine")
+ return;
+
+ boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
+ anAttr->setFeature(theFeature);
+}
+
+void PartSet_OperationConstraint::setValue(const double theValue)
+{
+ boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+
+ boost::shared_ptr<ModelAPI_AttributeDouble> anAttr =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
+ anAttr->setValue(theValue);
+
+}
public:
/// Returns the operation type key
- static std::string Type() { return "SketchConstraintDistance"; }
+ static std::string Type() { return "SketchConstraintLength"; }
public:
/// Constructor
/// \returns the created feature
virtual boost::shared_ptr<ModelAPI_Feature> createFeature(const bool theFlushMessage = true);
+ /// Set the feature for the constraint
+ /// \param theFeature the line feature
+ void setFeature(boost::shared_ptr<ModelAPI_Feature> theFeature);
+
+ /// Set the value for the constraint
+ /// \param theValue the constraint value
+ void setValue(const double theValue);
+
private:
boost::shared_ptr<ModelAPI_Feature> mySketch; ///< the sketch feature
};
#include <AIS_Shape.hxx>
#include <AIS_ListOfInteractive.hxx>
#include <AIS_InteractiveObject.hxx>
+#include <AIS_DimensionOwner.hxx>
+#include <AIS_LengthDimension.hxx>
#include <V3d_View.hxx>
#ifdef _DEBUG
using namespace std;
-const Quantity_NameOfColor SKETCH_PLANE_COLOR = Quantity_NOC_CHOCOLATE; /// the plane edge color
-const int SKETCH_WIDTH = 4; /// the plane edge width
-
PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId,
QObject* theParent)
: PartSet_OperationSketchBase(theId, theParent)
aModes.push_back(TopAbs_FACE);
else
aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature);
+
return aModes;
}
}
}
+#include <QLineEdit>
+void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
+ const std::list<XGUI_ViewerPrs>& theSelected,
+ const std::list<XGUI_ViewerPrs>& theHighlighted)
+{
+ if (!hasSketchPlane()) {
+ }
+ else {
+ if (!theSelected.empty()) {
+ XGUI_ViewerPrs aPrs = theSelected.front();
+ if (!aPrs.owner().IsNull()) {
+ Handle(AIS_DimensionOwner) anOwner = Handle(AIS_DimensionOwner)::DownCast(aPrs.owner());
+ if (!anOwner.IsNull() && anOwner->SelectionMode() == AIS_DSM_Text) {
+ Handle(SelectMgr_SelectableObject) anObject = anOwner->Selectable();
+ double aValue = 0;
+ if (!anObject.IsNull()) {
+ Handle(AIS_LengthDimension) aLenDim = Handle(AIS_LengthDimension)::DownCast(anObject);
+ if (!aLenDim.IsNull())
+ aValue = aLenDim->GetValue();
+ }
+
+ QLineEdit* aLine = new QLineEdit();
+ QPoint aViewPos = theEvent->globalPos();
+ QPoint aLinePos(aViewPos.x(), aViewPos.y());
+ aLine->move(aLinePos);
+ aLine->setText(QString::number(aValue));
+ aLine->show();
+ }
+ }
+ }
+ }
+}
+
void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
{
if (!hasSketchPlane() || !(theEvent->buttons() & Qt::LeftButton) || myFeatures.empty())
return hasSketchPlane();
}
-void PartSet_OperationSketch::correctPresentation(Handle(AIS_InteractiveObject) thePresentation)
-{
- Handle(AIS_Shape) anAIS = Handle(AIS_Shape)::DownCast(thePresentation);
- if (anAIS.IsNull())
- return;
-
- anAIS->SetColor(Quantity_Color(SKETCH_PLANE_COLOR));
- anAIS->SetWidth(SKETCH_WIDTH);
- anAIS->Redisplay();
-}
-
void PartSet_OperationSketch::startOperation()
{
if (!feature()) {
virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
const std::list<XGUI_ViewerPrs>& theSelected,
const std::list<XGUI_ViewerPrs>& theHighlighted);
+ /// Processes the mouse release in the point
+ /// \param theEvent the mouse event
+ /// \param theView a viewer to have the viewer the eye position
+ /// \param theSelected the list of selected presentations
+ /// \param theHighlighted the list of highlighted presentations
+ virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
+ const std::list<XGUI_ViewerPrs>& theSelected,
+ const std::list<XGUI_ViewerPrs>& theHighlighted);
+
/// Gives the current mouse point in the viewer
/// \param thePoint a point clicked in the viewer
/// \param theEvent the mouse event
/// \return enabled state
virtual bool isNestedOperationsEnabled() const;
- /// Corrects the presentation settings by the operation
- /// thePresentation an operation presentation
- void correctPresentation(Handle_AIS_InteractiveObject thePresentation);
-
signals:
/// signal about the sketch plane is selected
/// \param theX the value in the X direction of the plane
--- /dev/null
+// File: PartSet_Presentation.h
+// Created: 02 June 2014
+// Author: Natalia ERMOLAEVA
+
+#include <PartSet_Presentation.h>
+#include <PartSet_Tools.h>
+
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Data.h>
+
+#include <GeomDataAPI_Point.h>
+#include <GeomDataAPI_Point2D.h>
+#include <GeomDataAPI_Dir.h>
+
+#include <SketchPlugin_Sketch.h>
+#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Constraint.h>
+
+#include <AIS_InteractiveObject.hxx>
+#include <AIS_LengthDimension.hxx>
+#include <AIS_Shape.hxx>
+
+#include <gp_Pln.hxx>
+#include <gp_Pnt.hxx>
+
+const Quantity_NameOfColor SKETCH_PLANE_COLOR = Quantity_NOC_CHOCOLATE; /// the plane edge color
+const int SKETCH_WIDTH = 4; /// the plane edge width
+
+Handle(AIS_InteractiveObject) PartSet_Presentation::createPresentation(
+ boost::shared_ptr<ModelAPI_Feature> theFeature,
+ boost::shared_ptr<ModelAPI_Feature> theSketch,
+ const TopoDS_Shape& theShape,
+ Handle_AIS_InteractiveObject thePrevPrs)
+{
+ Handle(AIS_InteractiveObject) anAIS;
+
+ if (theFeature->getKind() == "SketchConstraintLength")
+ anAIS = createSketchConstraintLength(theFeature, theSketch, thePrevPrs);
+ else {
+ anAIS = createFeature(theFeature, theShape, thePrevPrs);
+ if (theFeature->getKind() == "Sketch")
+ {
+ Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS);
+ aShapeAIS->SetColor(Quantity_Color(SKETCH_PLANE_COLOR));
+ aShapeAIS->SetWidth(SKETCH_WIDTH);
+ aShapeAIS->Redisplay();
+ }
+ }
+
+ return anAIS;
+}
+
+Handle(AIS_InteractiveObject) PartSet_Presentation::createFeature(
+ boost::shared_ptr<ModelAPI_Feature> theFeature,
+ const TopoDS_Shape& theShape,
+ Handle_AIS_InteractiveObject thePrevPrs)
+{
+ Handle(AIS_InteractiveObject) anAIS = thePrevPrs;
+ if (!anAIS.IsNull())
+ {
+ Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS);
+ if (!aShapeAIS.IsNull()) {
+ // if the AIS object is displayed in the opened local context in some mode, additional
+ // AIS sub objects are created there. They should be rebuild for correct selecting.
+ // It is possible to correct it by closing local context before the shape set and opening
+ // after. Another workaround to thrown down the selection and reselecting the AIS.
+ // If there was a problem here, try the first solution with close/open local context.
+ aShapeAIS->Set(theShape);
+ aShapeAIS->Redisplay(Standard_True);
+ }
+ }
+ else
+ {
+ anAIS = new AIS_Shape(theShape);
+ }
+ return anAIS;
+}
+
+Handle(AIS_InteractiveObject) PartSet_Presentation::createSketchConstraintLength(
+ boost::shared_ptr<ModelAPI_Feature> theFeature,
+ boost::shared_ptr<ModelAPI_Feature> theSketch,
+ Handle(AIS_InteractiveObject) thePrevPrs)
+{
+ if (!theFeature || !theSketch)
+ return thePrevPrs;
+
+ boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
+ boost::shared_ptr<GeomDataAPI_Point> anOrigin =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
+ boost::shared_ptr<GeomDataAPI_Dir> aNormal =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
+ gp_Pln aPlane(aNormal->x(), aNormal->y(), aNormal->z(), 0/*D*/);
+
+ aData = theFeature->data();
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
+ if (!anAttr)
+ return thePrevPrs;
+ boost::shared_ptr<ModelAPI_Feature> aFeature = anAttr->feature();
+ if (!aFeature || aFeature->getKind() != "SketchLine")
+ return thePrevPrs;
+
+ aData = aFeature->data();
+ if (!aData->isValid())
+ return thePrevPrs;
+
+ boost::shared_ptr<GeomDataAPI_Point2D> aPointStart =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
+ boost::shared_ptr<GeomDataAPI_Point2D> aPointEnd =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
+
+ gp_Pnt aPoint1, aPoint2;
+ PartSet_Tools::ConvertTo3D(aPointStart->x(), aPointStart->y(), theSketch, aPoint1);
+ PartSet_Tools::ConvertTo3D(aPointEnd->x(), aPointEnd->y(), theSketch, aPoint2);
+
+ //Build dimension here
+ gp_Pnt aP1 = aPoint1;
+ gp_Pnt aP2 = aPoint2;
+
+ Handle(AIS_InteractiveObject) anAIS = thePrevPrs;
+ if (anAIS.IsNull())
+ {
+ Handle(AIS_LengthDimension) aLenDim = new AIS_LengthDimension (aP1, aP2, aPlane);
+
+ Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
+ anAspect->MakeArrows3d (Standard_False);
+ anAspect->MakeText3d(false/*is text 3d*/);
+ anAspect->TextAspect()->SetHeight(28);
+ anAspect->MakeTextShaded(false/*is test shaded*/);
+ aLenDim->DimensionAspect()->MakeUnitsDisplayed(false/*is units displayed*/);
+ /*if (isUnitsDisplayed)
+ {
+ aLenDim->SetDisplayUnits (aDimDlg->GetUnits ());
+ }*/
+ aLenDim->SetDimensionAspect (anAspect);
+ aLenDim->SetFlyout(12);
+
+ anAIS = aLenDim;
+ }
+ else {
+ // update presentation
+ Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS);
+ if (!aDimAIS.IsNull()) {
+ aDimAIS->SetMeasuredGeometry(aPoint1, aPoint2, aPlane);
+ aDimAIS->Redisplay(Standard_True);
+ }
+ }
+ return anAIS;
+}
--- /dev/null
+// File: PartSet_Presentation.h
+// Created: 02 Jun 2014
+// Author: Natalia ERMOLAEVA
+
+#ifndef PartSet_Presentation_H
+#define PartSet_Presentation_H
+
+#include "PartSet.h"
+
+#include <TopoDS_Shape.hxx>
+
+#include <boost/shared_ptr.hpp>
+
+class ModelAPI_Feature;
+class Handle_AIS_InteractiveObject;
+
+/*!
+ \class PartSet_Presentation
+ * \brief The operation for the sketch feature creation
+*/
+class PARTSET_EXPORT PartSet_Presentation
+{
+public:
+ /// Creates AIS presentation for the given feature
+ /// \param theFeature a feature
+ /// \return the presentation
+ static Handle_AIS_InteractiveObject createPresentation(
+ boost::shared_ptr<ModelAPI_Feature> theFeature,
+ boost::shared_ptr<ModelAPI_Feature> theSketch,
+ const TopoDS_Shape& theShape,
+ Handle_AIS_InteractiveObject thePrevPrs);
+protected:
+ static Handle_AIS_InteractiveObject createFeature(
+ boost::shared_ptr<ModelAPI_Feature> theFeature,
+ const TopoDS_Shape& theShape,
+ Handle_AIS_InteractiveObject thePrevPrs);
+
+ static Handle_AIS_InteractiveObject createSketchConstraintLength(
+ boost::shared_ptr<ModelAPI_Feature> theFeature,
+ boost::shared_ptr<ModelAPI_Feature> theSketch,
+ Handle_AIS_InteractiveObject thePrevPrs);
+};
+
+#endif
#include <XGUI_ViewerPrs.h>
#include <XGUI_ViewerProxy.h>
#include <PartSet_OperationSketchLine.h>
+#include <PartSet_Presentation.h>
#include <ModelAPI_Feature.h>
boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchLine::preview(aFeature);
XGUI_Displayer* aDisplayer = theWorkshop->displayer();
- aDisplayer->Redisplay(aFeature, aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), false);
+
+ Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation(
+ aFeature, aSketch,
+ aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), NULL);
+ if (!anAIS.IsNull())
+ aDisplayer->Redisplay(aFeature, anAIS, -1, false);
+
std::list<int> aModes;
aModes.push_back(TopAbs_VERTEX);
aModes.push_back(TopAbs_EDGE);
aDelta = aDelta - i*2;
PartSet_OperationSketchLine::setLinePoint(aFeature, 100+aDelta, 200+aDelta, LINE_ATTR_START);
PartSet_OperationSketchLine::setLinePoint(aFeature, 300+aDelta, 500+aDelta, LINE_ATTR_END);
- boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchLine::preview(aFeature);
- theWorkshop->displayer()->Redisplay(aFeature, aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), true);
+ boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchLine::preview(aFeature);
+ Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation(
+ aFeature, aSketch,
+ aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), NULL);
+ if (!anAIS.IsNull())
+ aDisplayer->Redisplay(aFeature, anAIS, -1, true);
int aVal = 90;
for (int j = 0; j < 10000000; j++)
myTestFeature = aFeature;
std::list<XGUI_ViewerPrs> aPrs;
- aPrs.push_back(XGUI_ViewerPrs(myTestFeature, TopoDS_Shape()));
+ aPrs.push_back(XGUI_ViewerPrs(myTestFeature, TopoDS_Shape(), NULL));
aDisplayer->SetSelected(aPrs, true);
}
}
PartSet_OperationSketchLine::setLinePoint(aFeature, 200/*aDelta*2*/, 200/*aDelta*2*/, LINE_ATTR_END);
boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchLine::preview(aFeature);
- theWorkshop->displayer()->Redisplay(aFeature, aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), true);
+ Handle(AIS_InteractiveObject) aPrevAIS;
+ boost::shared_ptr<ModelAPI_Feature> aSketch;//NULL
+ Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation(
+ aFeature, aSketch,
+ aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(),
+ aPrevAIS);
+ if (!anAIS.IsNull())
+ theWorkshop->displayer()->Redisplay(aFeature, anAIS, -1, true);
//std::list<int> aModes;
//aModes.clear();
//aModes.push_back(TopAbs_VERTEX);
theY = aVec.X() * anY->x() + aVec.Y() * anY->y() + aVec.Z() * anY->z();
}
+void PartSet_Tools::ConvertTo3D(const double theX, const double theY,
+ boost::shared_ptr<ModelAPI_Feature> theSketch,
+ gp_Pnt& thePoint)
+{
+ if (!theSketch)
+ return;
+
+ boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
+
+ boost::shared_ptr<GeomDataAPI_Point> aC =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
+ boost::shared_ptr<GeomDataAPI_Dir> aX =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRX));
+ boost::shared_ptr<GeomDataAPI_Dir> aY =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_DIRY));
+
+ boost::shared_ptr<GeomAPI_XYZ> aSum = aC->pnt()->xyz()->added(
+ aX->dir()->xyz()->multiplied(theX))->added(aY->dir()->xyz()->multiplied(theY));
+
+ boost::shared_ptr<GeomAPI_Pnt> aPoint = boost::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum));
+ thePoint = gp_Pnt(aPoint->x(), aPoint->y(), aPoint->z());
+}
+
void PartSet_Tools::IntersectLines(double theX0, double theY0, double theX1, double theY1,
double theX2, double theY2, double theX3, double theY3,
double& theX, double& theY)
static void ConvertTo2D(const gp_Pnt& thePoint, boost::shared_ptr<ModelAPI_Feature> theSketch,
Handle(V3d_View) theView, double& theX, double& theY);
+ /// \brief Converts the 2D projected coodinates on the sketch plane to the 3D point.
+ /// \param theX the X coordinate
+ /// \param theY the Y coordinate
+ /// \param theSketch the sketch feature
+ /// \param thePoint the 3D point in the viewer
+ static void ConvertTo3D(const double theX, const double theY,
+ boost::shared_ptr<ModelAPI_Feature> theSketch,
+ gp_Pnt& thePoint);
+
/// Returns the point of intersection of the two lines, the first is (v0, v1), the second is (v2, v3),
/// where vi - {xi,yi}. If the v0 is on the second line, the result is a projection of the v1 to this line
/// \param theX0 the horizontal coordinate of 0 point
ModelAPI
)
+SET(XML_RESOURCES
+ plugin-Sketch.xml
+)
+
ADD_DEFINITIONS(-DSKETCHPLUGIN_EXPORTS ${BOOST_DEFINITIONS})
-ADD_LIBRARY(SketchPlugin MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS})
+ADD_LIBRARY(SketchPlugin MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${XML_RESOURCES})
TARGET_LINK_LIBRARIES(SketchPlugin ${PROJECT_LIBRARIES})
INCLUDE_DIRECTORIES(
../GeomDataAPI
)
-SET(XML_RESOURCES
- plugin-Sketch.xml
-)
-
INSTALL(TARGETS SketchPlugin DESTINATION plugins)
INSTALL(FILES ${XML_RESOURCES} DESTINATION plugins)
<plugin>
<workbench id="Sketch">
<group id="Basic">
- <feature id="Sketch" nested="SketchLine SketchConstraintDistance" title="Sketch" tooltip="Create a new sketch or edit an existing sketch" icon=":icons/sketch.png">
+ <feature id="Sketch" nested="SketchLine SketchConstraintLength" title="Sketch" tooltip="Create a new sketch or edit an existing sketch" icon=":icons/sketch.png">
<label title="Select a plane on which to create a sketch" tooltip="Select a plane on which to create a sketch"/>
<!--icon=":pictures/x_point.png"-->
</feature>
<point_selector id="ArcEndPoint" title="End point" tooltip="End point of the arc"/>
</feature>
<feature id="SketchConstraintCoincidence" title="Points coincidence" tooltip="Create constraint for the coincidence of two points" internal="1"/>
- <feature id="SketchConstraintDistance" title="Distance between objects" tooltip="Create constraint for the distance from a point to an object"/>
- <feature id="SketchConstraintLength" title="Length of a line" tooltip="Create constraint for the given length of a line segment" internal="1"/>
+ <feature id="SketchConstraintDistance" title="Distance between objects" tooltip="Create constraint for the distance from a point to an object" internal="1"/>
+ <feature id="SketchConstraintLength" title="Length of a line" tooltip="Create constraint for the given length of a line segment">
+ <label title="Select a line entity on which to calculate lenght" tooltip="Select a line entity on which to calculate lenght"/>
+ </feature>
<feature id="SketchConstraintRadius" title="Radius of a circle or an arc" tooltip="Create constraint for the given radius of a circle or an arc" internal="1"/>
<feature id="SketchConstraintParallel" title="Parallelism of a lines" tooltip="Create constraint defining two parallel lines" internal="1"/>
<feature id="SketchConstraintPerpendicular" title="Orthgonality of a lines" tooltip="Create constraint defining two perpendicular lines" internal="1"/>
theConstraint->data()->attribute(CONSTRAINT_ATTRIBUTES[indAttr])
);
if (!anAttr) continue;
- if (anAttr->isFeature())
+ if (anAttr->isFeature() && anAttr->feature())
{ // verify posiible entities
const std::string& aKind = anAttr->feature()->getKind();
if (aKind.compare("SketchPoint") == 0)
theConstraint->data()->attribute(CONSTRAINT_ATTRIBUTES[indAttr])
);
if (!anAttr) continue;
- if (anAttr->isFeature() && anAttr->feature()->getKind().compare("SketchLine") == 0)
+ if (anAttr->isFeature() && anAttr->feature() &&
+ anAttr->feature()->getKind().compare("SketchLine") == 0)
{
myAttributesList[aNbLines++] = CONSTRAINT_ATTRIBUTES[indAttr];
break;
#include <AIS_LocalContext.hxx>
#include <AIS_ListOfInteractive.hxx>
#include <AIS_ListIteratorOfListOfInteractive.hxx>
+#include <AIS_DimensionSelectionMode.hxx>
#include <AIS_Shape.hxx>
for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
TopoDS_Shape aShape = aContext->SelectedShape();
+
if (theShapeTypeToSkip >= 0 && !aShape.IsNull() && aShape.ShapeType() == theShapeTypeToSkip)
continue;
boost::shared_ptr<ModelAPI_Feature> aFeature = GetFeature(anIO);
if (aPrsFeatures.find(aFeature) != aPrsFeatures.end())
continue;
- aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape));
+ Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
+ aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape, anOwner));
aPrsFeatures.insert(aFeature);
}
return aPresentations;
boost::shared_ptr<ModelAPI_Feature> aFeature = GetFeature(anIO);
if (aPrsFeatures.find(aFeature) != aPrsFeatures.end())
continue;
- aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape));
+ aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape, NULL));
aPrsFeatures.insert(aFeature);
}
}
bool XGUI_Displayer::Redisplay(boost::shared_ptr<ModelAPI_Feature> theFeature,
- const TopoDS_Shape& theShape, const bool isUpdateViewer)
+ Handle(AIS_InteractiveObject) theAIS,
+ const int theSelectionMode,
+ const bool isUpdateViewer)
{
bool isCreated = false;
Handle(AIS_InteractiveContext) aContext = AISContext();
//aContext->SetPixelTolerance(MOUSE_SENSITIVITY_IN_PIXEL);
}
// display or redisplay presentation
- Handle(AIS_Shape) anAIS;
- if (IsVisible(theFeature)) {
- anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[theFeature]);
- if (!anAIS.IsNull()) {
- // if the AIS object is displayed in the opened local context in some mode, additional
- // AIS sub objects are created there. They should be rebuild for correct selecting.
- // It is possible to correct it by closing local context before the shape set and opening
- // after. Another workaround to thrown down the selection and reselecting the AIS.
- // If there was a problem here, try the first solution with close/open local context.
- anAIS->Set(theShape);
- anAIS->Redisplay(Standard_True);
- aContext->RecomputeSelectionOnly(anAIS);
- }
+ if (IsVisible(theFeature) && !myFeature2AISObjectMap[theFeature].IsNull()) {
+ aContext->RecomputeSelectionOnly(theAIS);
}
else {
- anAIS = new AIS_Shape(theShape);
- myFeature2AISObjectMap[theFeature] = anAIS;
- aContext->Display(anAIS, false);
+ myFeature2AISObjectMap[theFeature] = theAIS;
+ if (theSelectionMode < 0)
+ {
+ aContext->Display(theAIS, false);
+ }
+ else
+ {
+ aContext->Display(theAIS, 0, theSelectionMode, false);
+ }
isCreated = true;
}
if (isUpdateViewer)
/// Display the shape and activate selection of sub-shapes
/// \param theFeature a feature instance
- /// \param theShape a shape
- /// \param theMode a local selection mode
+ /// \param theAIS an AIS object
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
/// \returns true if the presentation is created
bool Redisplay(boost::shared_ptr<ModelAPI_Feature> theFeature,
- const TopoDS_Shape& theShape, const bool isUpdateViewer = true);
+ Handle(AIS_InteractiveObject) theAIS,
+ const int theSelectionMode, const bool isUpdateViewer = true);
+
+ /// Redisplay the shape and activate selection of sub-shapes
+ /// \param theFeature a feature instance
+ /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
+ //void Redisplay(Handle(AIS_InteractiveObject) theAIS, const bool isUpdateViewer = true);
/// Display the shape and activate selection of sub-shapes
/// \param theFeature a feature instance
#include "XGUI_ViewerPrs.h"
+#include "SelectMgr_EntityOwner.hxx"
+
XGUI_ViewerPrs::XGUI_ViewerPrs()
{
}
XGUI_ViewerPrs::XGUI_ViewerPrs(boost::shared_ptr<ModelAPI_Feature> theFeature,
- const TopoDS_Shape& theShape)
-: myFeature(theFeature), myShape(theShape)
+ const TopoDS_Shape& theShape,
+ Handle(SelectMgr_EntityOwner) theOwner)
+: myFeature(theFeature), myShape(theShape), myOwner(theOwner)
{
}
myFeature = theFeature;
}
-void XGUI_ViewerPrs::setShape(const TopoDS_Shape& theShape)
+boost::shared_ptr<ModelAPI_Feature> XGUI_ViewerPrs::feature() const
{
- myShape = theShape;
+ return myFeature;
}
-boost::shared_ptr<ModelAPI_Feature> XGUI_ViewerPrs::feature() const
+void XGUI_ViewerPrs::setOwner(Handle(SelectMgr_EntityOwner) theOwner)
{
- return myFeature;
+ myOwner = theOwner;
+}
+
+Handle(SelectMgr_EntityOwner) XGUI_ViewerPrs::owner() const
+{
+ return myOwner;
+}
+
+void XGUI_ViewerPrs::setShape(const TopoDS_Shape& theShape)
+{
+ myShape = theShape;
}
const TopoDS_Shape& XGUI_ViewerPrs::shape() const
#include <boost/shared_ptr.hpp>
#include <TopoDS_Shape.hxx>
+#include <SelectMgr_EntityOwner.hxx>
class ModelAPI_Feature;
/**\class XGUI_ViewerPrs
* \ingroup GUI
- * \brief Presentation. Provides container to have feature and the shape
+ * \brief Presentation. Provides container to have feature, shape and/or selection owner.
*/
class XGUI_EXPORT XGUI_ViewerPrs
{
/// Constructor
XGUI_ViewerPrs();
/// Constructor
+ /// \param theFeature a model feature
+ /// \param theShape a viewer shape
+ /// \param theOwner a selection owner
XGUI_ViewerPrs(boost::shared_ptr<ModelAPI_Feature> theFeature,
- const TopoDS_Shape& theShape);
+ const TopoDS_Shape& theShape,
+ Handle_SelectMgr_EntityOwner theOwner);
/// Destructor
virtual ~XGUI_ViewerPrs();
/// \param theFeature a feature instance
void setFeature(boost::shared_ptr<ModelAPI_Feature> theFeature);
- /// Sets the shape
- /// \param theShape a shape instance
- void setShape(const TopoDS_Shape& theShape);
-
/// Returns the feature.
/// \return a feature instance
boost::shared_ptr<ModelAPI_Feature> feature() const;
+ /// Returns the presentation owner
+ /// \param the owner
+ void setOwner(Handle_SelectMgr_EntityOwner theOwner);
+
+ /// Returns the presentation owner
+ /// \return an owner
+ Handle_SelectMgr_EntityOwner owner() const;
+
+ /// Sets the shape
+ /// \param theShape a shape instance
+ void setShape(const TopoDS_Shape& theShape);
+
/// Returns the shape
/// \return a shape instance
const TopoDS_Shape& shape() const;
private:
boost::shared_ptr<ModelAPI_Feature> myFeature; /// the feature
+ Handle(SelectMgr_EntityOwner) myOwner; /// the selection owner
TopoDS_Shape myShape; /// the shape
};