Continuous line creation.
{
if (QString(theMessage->eventID().eventText()) == EVENT_FEATURE_UPDATED)
{
- myModule->visualizePreview(true);
+ const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
+ boost::shared_ptr<ModelAPI_Feature> aFeature = aUpdMsg->feature();
+ myModule->visualizePreview(aFeature, true);
}
}
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
if (aPreviewOp) {
- visualizePreview(true);
+ visualizePreview(aPreviewOp->feature(), true);
+
+ connect(aPreviewOp, SIGNAL(featureConstructed(boost::shared_ptr<ModelAPI_Feature>)),
+ this, SLOT(onFeatureConstructed(boost::shared_ptr<ModelAPI_Feature>)));
PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
if (aSketchOp) {
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
if (aPreviewOp) {
aPreviewOp->setEditMode(true);
- visualizePreview(false);
+ visualizePreview(aPreviewOp->feature(), false);
}
}
myWorkshop->actionsMgr()->setNestedActionsEnabled(true);
}
-void PartSet_Module::visualizePreview(bool isDisplay)
+void PartSet_Module::onFeatureConstructed(boost::shared_ptr<ModelAPI_Feature> theFeature)
+{
+ visualizePreview(theFeature, true);
+}
+
+void PartSet_Module::visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFeature, bool isDisplay)
{
ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
if (!anOperation)
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
if (isDisplay) {
- boost::shared_ptr<GeomAPI_Shape> aPreview = aPreviewOp->preview();
+ boost::shared_ptr<GeomAPI_Shape> aPreview = aPreviewOp->preview(theFeature);
if (aPreview) {
- aDisplayer->DisplayInLocalContext(anOperation->feature(), aPreview->impl<TopoDS_Shape>(),
- aPreviewOp->getSelectionMode());
+ aDisplayer->DisplayInLocalContext(theFeature, aPreview->impl<TopoDS_Shape>(),
+ aPreviewOp->getSelectionMode(theFeature));
}
}
else {
#include <string>
+#include <boost/shared_ptr.hpp>
+
class XGUI_ViewWindow;
class QMouseEvent;
class PartSet_Listener;
+class ModelAPI_Feature;
class PARTSET_EXPORT PartSet_Module: public QObject, public XGUI_Module
{
virtual void launchOperation(const QString& theCmdId);
/// Displays or erase the current operation preview, if it has it.
+ /// \param theF
/// \param isDisplay the state whether the presentation should be displayed or erased
- void visualizePreview(bool isDisplay);
+ void visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFeature, bool isDisplay);
public slots:
void onFeatureTriggered();
/// \param theZ the Z projection value
void onPlaneSelected(double theX, double theY, double theZ);
+ /// SLOT, to visualize the feature in another local context mode
+ /// \param theFeature the feature to be put in another local context mode
+ void onFeatureConstructed(boost::shared_ptr<ModelAPI_Feature> theFeature);
+
private:
XGUI_Workshop* myWorkshop;
PartSet_Listener* myListener;
{
}
-int PartSet_OperationSketch::getSelectionMode() const
+int PartSet_OperationSketch::getSelectionMode(boost::shared_ptr<ModelAPI_Feature> theFeature) const
{
int aMode = TopAbs_FACE;
if (isEditMode())
virtual ~PartSet_OperationSketch();
/// Returns the operation local selection mode
+ /// \param theFeature the feature object to get the selection mode
/// \return the selection mode
- virtual int getSelectionMode() const;
+ virtual int getSelectionMode(boost::shared_ptr<ModelAPI_Feature> theFeature) const;
/// Gives the current selected objects to be processed by the operation
/// \param theList a list of interactive selected shapes
{
}
-boost::shared_ptr<GeomAPI_Shape> PartSet_OperationSketchBase::preview() const
+boost::shared_ptr<GeomAPI_Shape> PartSet_OperationSketchBase::preview(
+ boost::shared_ptr<ModelAPI_Feature> theFeature) const
{
boost::shared_ptr<SketchPlugin_Feature> aFeature =
- boost::dynamic_pointer_cast<SketchPlugin_Feature>(feature());
+ boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
return aFeature->preview();
}
virtual ~PartSet_OperationSketchBase();
/// Returns the feature preview shape
- boost::shared_ptr<GeomAPI_Shape> preview() const;
+ /// \param theFeature the feature object to obtain the preview
+ boost::shared_ptr<GeomAPI_Shape> preview(boost::shared_ptr<ModelAPI_Feature> theFeature) const;
/// Returns the operation local selection mode
+ /// \param theFeature the feature object to get the selection mode
/// \return the selection mode
- virtual int getSelectionMode() const = 0;
+ virtual int getSelectionMode(boost::shared_ptr<ModelAPI_Feature> theFeature) const = 0;
/// Gives the current selected objects to be processed by the operation
/// \param theList a list of interactive selected shapes
/// \param thePoint a 3D point clicked in the viewer
virtual void mouseMoved(const gp_Pnt& thePoint) {};
+signals:
+ /// Signal about the feature construing is finished
+ /// \param theFeature the result feature
+ void featureConstructed(boost::shared_ptr<ModelAPI_Feature> theFeature);
+
+public:
/// temporary code to provide edition mode
void setEditMode(const bool isEditMode) { myIsEditMode = isEditMode; };
protected:
#include <GeomDataAPI_Point.h>
#include <GeomDataAPI_Dir.h>
#include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
#include <SketchPlugin_Sketch.h>
#include <SketchPlugin_Line.h>
return true;
}
-int PartSet_OperationSketchLine::getSelectionMode() const
+int PartSet_OperationSketchLine::getSelectionMode(boost::shared_ptr<ModelAPI_Feature> theFeature) const
{
- return 0;//TopAbs_FACE;
+ int aMode = 0;
+ if (theFeature != feature())
+ aMode = TopAbs_VERTEX;
+ return aMode;
}
void PartSet_OperationSketchLine::mouseReleased(const gp_Pnt& thePoint)
void PartSet_OperationSketchLine::mouseMoved(const gp_Pnt& thePoint)
{
- if (myPointSelectionMode == SM_SecondPoint)
- setLinePoint(thePoint, LINE_ATTR_END);
+ switch (myPointSelectionMode)
+ {
+ case SM_SecondPoint:
+ setLinePoint(thePoint, LINE_ATTR_END);
+ break;
+ case SM_None: {
+ boost::shared_ptr<ModelAPI_Feature> aPrevFeature = feature();
+ // stop the last operation
+ commitOperation();
+ document()->finishOperation();
+ //emit changeSelectionMode(aPrevFeature, TopAbs_VERTEX);
+ // start a new operation
+ document()->startOperation();
+ startOperation();
+ // use the last point of the previous feature as the first of the new one
+ setLinePoint(aPrevFeature, LINE_ATTR_END, LINE_ATTR_START);
+ myPointSelectionMode = SM_SecondPoint;
+
+ emit featureConstructed(aPrevFeature);
+ }
+ break;
+ default:
+ break;
+ }
}
void PartSet_OperationSketchLine::startOperation()
aPoint->setValue(aX, anY);
}
+void PartSet_OperationSketchLine::setLinePoint(boost::shared_ptr<ModelAPI_Feature> theSourceFeature,
+ const std::string& theSourceAttribute,
+ const std::string& theAttribute)
+{
+ boost::shared_ptr<ModelAPI_Data> aData = theSourceFeature->data();
+ boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+ boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theSourceAttribute));
+ double aX = aPoint->x();
+ double anY = aPoint->y();
+
+ aData = feature()->data();
+ aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(theAttribute));
+ aPoint->setValue(aX, anY);
+}
+
void PartSet_OperationSketchLine::convertTo2D(const gp_Pnt& thePoint, double& theX, double& theY)
{
if (!mySketch)
virtual bool isGranted() const;
/// Returns the operation local selection mode
+ /// \param theFeature the feature object to get the selection mode
/// \return the selection mode
- virtual int getSelectionMode() const;
+ virtual int getSelectionMode(boost::shared_ptr<ModelAPI_Feature> theFeature) const;
/// Gives the current selected objects to be processed by the operation
/// \param thePoint a point clicked in the viewer
/// \param thePoint a point clicked in the viewer
virtual void mouseMoved(const gp_Pnt& thePoint);
+signals:
+ /// signal about the sketch plane is selected
+ /// \param theX the value in the X direction of the plane
+ /// \param theX the value in the Y direction value of the plane
+ /// \param theX the value in the Z direction of the plane
+ void localContextChanged(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ int theMode);
+
protected:
/// \brief Virtual method called when operation is started
/// Virtual method called when operation started (see start() method for more description)
/// \param theAttribute the start or end attribute of the line
void setLinePoint(const gp_Pnt& thePoint, const std::string& theAttribute);
+ /// \brief Set the point to the line by the point of the source line.
+ /// \param theSourceFeature the feature, where the point is obtained
+ /// \param theSourceAttribute the start or end attribute of the source line
+ /// \param theAttribute the start or end attribute of the line
+ void setLinePoint(boost::shared_ptr<ModelAPI_Feature> theSourceFeature,
+ const std::string& theSourceAttribute,
+ const std::string& theAttribute);
/// \brief Converts the 3D point to the projected coodinates on the sketch plane.
/// \param thePoint the 3D point in the viewer
/// \param theX the X coordinate