Start operation of line creation during the edit operation is active.
return myDescription;
}
-bool ModuleBase_IOperation::isGranted() const
+bool ModuleBase_IOperation::isGranted(ModuleBase_IOperation* /*theOperation*/) const
{
return false;
}
/// must be always can start above any launched one. Default impl returns FALSE,
/// so it is being checked for IsValid, but some operations may overload IsGranted()
/// In this case they will always start, no matter what operation is running.
- virtual bool isGranted() const;
+ /// \param theOperation the previous running operation
+ virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
signals:
void started(); /// the operation is started
else if(theCmdId == PartSet_OperationSketchLine::Type() ||
theCmdId == PartSet_OperationEditLine::Type()) {
ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
- boost::shared_ptr<ModelAPI_Feature> aSketchFeature;
- if (aCurOperation)
- aSketchFeature = aCurOperation->feature();
+ boost::shared_ptr<ModelAPI_Feature> aSketch;
+ PartSet_OperationSketchBase* aPrevOp = dynamic_cast<PartSet_OperationSketchBase*>(aCurOperation);
+ if (aPrevOp)
+ aSketch = aPrevOp->sketch();
if (theCmdId == PartSet_OperationSketchLine::Type())
- anOperation = new PartSet_OperationSketchLine(theCmdId.c_str(), this, aSketchFeature);
+ anOperation = new PartSet_OperationSketchLine(theCmdId.c_str(), this, aSketch);
else
- anOperation = new PartSet_OperationEditLine(theCmdId.c_str(), this, aSketchFeature);
+ anOperation = new PartSet_OperationEditLine(theCmdId.c_str(), this, aSketch);
}
else {
anOperation = new ModuleBase_Operation(theCmdId.c_str(), this);
#include <PartSet_OperationEditLine.h>
#include <PartSet_Tools.h>
+#include <PartSet_OperationSketch.h>
+
+#include <ModuleBase_OperationDescription.h>
#include <XGUI_ViewerPrs.h>
{
}
-bool PartSet_OperationEditLine::isGranted() const
+bool PartSet_OperationEditLine::isGranted(ModuleBase_IOperation* theOperation) const
{
- return true;
+ return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
}
std::list<int> PartSet_OperationEditLine::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
myFeatures = thePresentations;
}
+boost::shared_ptr<ModelAPI_Feature> PartSet_OperationEditLine::sketch() const
+{
+ return mySketch;
+}
+
void PartSet_OperationEditLine::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView)
{
if (!(theEvent->buttons() & Qt::LeftButton))
if (myCurPoint.myIsInitialized) {
double aCurX, aCurY;
- PartSet_Tools::ConvertTo2D(myCurPoint.myPoint, mySketch, theView, aCurX, aCurY);
+ PartSet_Tools::ConvertTo2D(myCurPoint.myPoint, sketch(), theView, aCurX, aCurY);
double aX, anY;
- PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY);
+ PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY);
double aDeltaX = aX - aCurX;
double aDeltaY = anY - aCurY;
/// Destructor
virtual ~PartSet_OperationEditLine();
- /// Returns that this operator can be started above already running one.
- /// The runned operation should be the sketch feature modified operation
- virtual bool isGranted() const;
+ /// Returns that this operator can be started above already running one.
+ /// The runned operation should be the sketch feature modified operation
+ /// \param theOperation the previous running operation
+ virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
/// Returns the operation local selection mode
/// \param theFeature the feature object to get the selection mode
virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
const std::list<XGUI_ViewerPrs>& thePresentations);
+ /// Returns the operation sketch feature
+ /// \returns the sketch instance
+ virtual boost::shared_ptr<ModelAPI_Feature> sketch() const;
+
/// Processes the mouse pressed in the point
/// \param thePoint a point clicked in the viewer
/// \param theEvent the mouse event
return aModes;
}
+boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketch::sketch() const
+{
+ return feature();
+}
+
void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
const std::list<XGUI_ViewerPrs>& theSelected)
{
/// \return the selection mode
virtual std::list<int> getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const;
+ /// Returns the operation sketch feature
+ /// \returns the sketch instance
+ virtual boost::shared_ptr<ModelAPI_Feature> sketch() const;
+
/// Processes the mouse pressed in the point
/// \param thePoint a point clicked in the viewer
/// \param theEvent the mouse event
virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
const std::list<XGUI_ViewerPrs>& thePresentations) {}
+ /// Returns the operation sketch feature
+ /// \returns the sketch instance
+ virtual boost::shared_ptr<ModelAPI_Feature> sketch() const = 0;
+
/// Processes the mouse pressed in the point
/// \param thePoint a point clicked in the viewer
/// \param theEvent the mouse event
#include <PartSet_OperationSketchLine.h>
#include <PartSet_Tools.h>
+#include <PartSet_OperationSketch.h>
#include <SketchPlugin_Feature.h>
#include <SketchPlugin_Sketch.h>
#include <GeomDataAPI_Point2D.h>
+
+#include <ModuleBase_OperationDescription.h>
+
#include <ModelAPI_Data.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_AttributeRefAttr.h>
{
}
-bool PartSet_OperationSketchLine::isGranted() const
+bool PartSet_OperationSketchLine::isGranted(ModuleBase_IOperation* theOperation) const
{
- return true;
+ return theOperation->getDescription()->operationId().toStdString() == PartSet_OperationSketch::Type();
}
std::list<int> PartSet_OperationSketchLine::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
myInitPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
}
+boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchLine::sketch() const
+{
+ return mySketch;
+}
+
void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
const std::list<XGUI_ViewerPrs>& theSelected)
{
bool isFoundPoint = false;
gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
if (theSelected.empty()) {
- PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY);
+ PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY);
isFoundPoint = true;
}
else {
const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
if (!aVertex.IsNull()) {
aPoint = BRep_Tool::Pnt(aVertex);
- PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, aX, anY);
+ PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY);
isFoundPoint = true;
setConstraints(aX, anY);
double Y0, Y1, Y2, Y3;
getLinePoint(aFeature, LINE_ATTR_START, X2, Y2);
getLinePoint(aFeature, LINE_ATTR_END, X3, Y3);
- PartSet_Tools::ConvertTo2D(aPoint, mySketch, theView, X1, Y1);
+ PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, X1, Y1);
switch (myPointSelectionMode) {
case SM_FirstPoint:
boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchLine::createFeature()
{
boost::shared_ptr<ModelAPI_Feature> aNewFeature = ModuleBase_Operation::createFeature();
- if (mySketch) {
+ if (sketch()) {
boost::shared_ptr<SketchPlugin_Feature> aFeature =
- boost::dynamic_pointer_cast<SketchPlugin_Feature>(mySketch);
+ boost::dynamic_pointer_cast<SketchPlugin_Feature>(sketch());
aFeature->addSub(aNewFeature);
}
boost::shared_ptr<ModelAPI_Document> aDoc = document();
boost::shared_ptr<ModelAPI_Feature> aFeature = aDoc->addFeature("SketchConstraintCoincidence");
- if (mySketch) {
+ if (sketch()) {
boost::shared_ptr<SketchPlugin_Feature> aSketch =
- boost::dynamic_pointer_cast<SketchPlugin_Feature>(mySketch);
+ boost::dynamic_pointer_cast<SketchPlugin_Feature>(sketch());
aSketch->addSub(aFeature);
}
boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
(aData->attribute(aPointArg));
- aData = mySketch->data();
+ aData = sketch()->data();
boost::shared_ptr<ModelAPI_AttributeRefList> aRefList =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aData->attribute(SKETCH_ATTR_FEATURES));
const std::string& theAttribute)
{
double aX, anY;
- PartSet_Tools::ConvertTo2D(thePoint, mySketch, theView, aX, anY);
+ PartSet_Tools::ConvertTo2D(thePoint, sketch(), theView, aX, anY);
boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
/// Returns that this operator can be started above already running one.
/// The runned operation should be the sketch feature modified operation
- virtual bool isGranted() const;
+ /// \param theOperation the previous running operation
+ virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
/// Returns the operation local selection mode
/// \param theFeature the feature object to get the selection mode
virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
const std::list<XGUI_ViewerPrs>& thePresentations);
+ /// Returns the operation sketch feature
+ /// \returns the sketch instance
+ virtual boost::shared_ptr<ModelAPI_Feature> sketch() const;
+
/// Gives the current selected objects to be processed by the operation
/// \param thePoint a point clicked in the viewer
/// \param theEvent the mouse event
{
bool aCanStart = true;
ModuleBase_Operation* aCurrentOp = currentOperation();
- if (aCurrentOp && !theOperation->isGranted())
+ if (aCurrentOp && !theOperation->isGranted(aCurrentOp))
{
if (canStopOperation()) {
aCurrentOp->abort();