if (aStart.IsEqual(anEnd, Precision::Confusion()))
return boost::shared_ptr<GeomAPI_Shape>();
+ if (Abs(aStart.SquareDistance(anEnd)) > 1.e+100)
+ return boost::shared_ptr<GeomAPI_Shape>();
BRepBuilderAPI_MakeEdge anEdgeBuilder(aStart, anEnd);
boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
TopoDS_Edge anEdge = anEdgeBuilder.Edge();
#include <XGUI_ViewPort.h>
#include <XGUI_ActionsMgr.h>
#include <XGUI_ViewerProxy.h>
+#include <XGUI_ContextMenuMgr.h>
#include <Config_PointerMessage.h>
#include <Config_ModuleReader.h>
connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
this, SLOT(onOperationStopped(ModuleBase_Operation*)));
+ XGUI_ContextMenuMgr* aContextMenuMgr = myWorkshop->contextMenuMgr();
+ connect(aContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)),
+ this, SLOT(onContextMenuCommand(const QString&, bool)));
+
connect(myWorkshop->viewer(), SIGNAL(mousePress(QMouseEvent*)),
this, SLOT(onMousePressed(QMouseEvent*)));
connect(myWorkshop->viewer(), SIGNAL(mouseRelease(QMouseEvent*)),
std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->GetHighlighted(TopAbs_VERTEX);
aPreviewOp->init(theFeature, aSelected, aHighlighted);
}
- myWorkshop->actionsMgr()->updateCheckState();
sendOperation(anOperation);
+ myWorkshop->actionsMgr()->updateCheckState();
}
void PartSet_Module::onMultiSelectionEnabled(bool theEnabled)
void PartSet_Module::editFeature(FeaturePtr theFeature)
{
- /*if (!theFeature)
+ if (!theFeature)
return;
if (theFeature->getKind() == "Sketch") {
onLaunchOperation(theFeature->getKind(), theFeature);
- visualizePreview(theFeature, true);
- }*/
+ updateCurrentPreview(theFeature->getKind());
+ }
}
}
void PartSet_OperationSketch::init(boost::shared_ptr<ModelAPI_Feature> theFeature,
- const std::list<XGUI_ViewerPrs>& thePresentations)
+ const std::list<XGUI_ViewerPrs>& /*theSelected*/,
+ const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
{
setFeature(theFeature);
}
return hasSketchPlane();
}
+void PartSet_OperationSketch::startOperation()
+{
+ if (!feature())
+ setFeature(createFeature());
+}
+
bool PartSet_OperationSketch::hasSketchPlane() const
{
bool aHasPlane = false;
if (feature()) {
- // set plane parameters to feature
boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
-
boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
- // temporary solution for main planes only
boost::shared_ptr<GeomDataAPI_Dir> aNormal =
boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
- double aX = aNormal->x(), anY = aNormal->y(), aZ = aNormal->z();
-
aHasPlane = aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
}
return aHasPlane;
virtual std::list<int> getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const;
/// Initializes some fields accorging to the feature
- /// \param theFeature the feature
- /// \param thePresentations the list of additional presentations
+ /// \param theSelected the list of selected presentations
+ /// \param theHighlighted the list of highlighted presentations
virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
- const std::list<XGUI_ViewerPrs>& thePresentations);
+ const std::list<XGUI_ViewerPrs>& theSelected,
+ const std::list<XGUI_ViewerPrs>& theHighlighted);
/// Returns the operation sketch feature
/// \returns the sketch instance
void planeSelected(double theX, double theY, double theZ);
protected:
+ /// Virtual method called when operation started (see start() method for more description)
+ /// Default impl calls corresponding slot and commits immediately.
+ virtual void startOperation();
+
/// Returns whether the sketch plane is set
/// \return the boolean value whether the sketch is set
bool hasSketchPlane() const;
const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Sketch::preview()
{
- std::list<boost::shared_ptr<GeomAPI_Shape> > aFaces;
-
- addPlane(1, 0, 0, aFaces); // YZ plane
- addPlane(0, 1, 0, aFaces); // XZ plane
- addPlane(0, 0, 1, aFaces); // XY plane
- boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aFaces);
- setPreview(aCompound);
+ if (isPlaneSet()) {
+ setPreview(boost::shared_ptr<GeomAPI_Shape>());
+ }
+ else {
+ std::list<boost::shared_ptr<GeomAPI_Shape> > aFaces;
+ addPlane(1, 0, 0, aFaces); // YZ plane
+ addPlane(0, 1, 0, aFaces); // XZ plane
+ addPlane(0, 0, 1, aFaces); // XY plane
+ boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aFaces);
+ setPreview(aCompound);
+ }
return getPreview();
}
return boost::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum));
}
+
+bool SketchPlugin_Sketch::isPlaneSet()
+{
+ boost::shared_ptr<GeomDataAPI_Dir> aNormal =
+ boost::dynamic_pointer_cast<GeomDataAPI_Dir>(data()->attribute(SKETCH_ATTR_NORM));
+
+ return aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
+}
/// \param theShapes the list of result shapes
void addPlane(double theX, double theY, double theZ,
std::list<boost::shared_ptr<GeomAPI_Shape> >& theShapes) const;
+
+ /// Checks whether the plane is set in the sketch.
+ /// \returns the boolean state
+ bool isPlaneSet();
};
#endif
myPropertyPanel->setModelWidgets(aFactory.getModelWidgets());
myPropertyPanel->setWindowTitle(aOperation->getDescription()->description());
}
+ updateCommandStatus();
}
//******************************************************