return MY_PNT->Distance(theOther->impl<gp_Pnt>());
}
+bool GeomAPI_Pnt::isEqual(const std::shared_ptr<GeomAPI_Pnt>& theOther) const
+{
+ return distance(theOther) < Precision::Confusion();
+}
+
std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Pnt::to2D(const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
const std::shared_ptr<GeomAPI_Dir>& theDirX, const std::shared_ptr<GeomAPI_Dir>& theDirY)
{
GEOMAPI_EXPORT
double distance(const std::shared_ptr<GeomAPI_Pnt>& theOther) const;
+ /// Returns whether the distance between two points is less then precision confusion
+ GEOMAPI_EXPORT
+ bool isEqual(const std::shared_ptr<GeomAPI_Pnt>& theOther) const;
+
/// Projects a point to the plane defined by the origin and 2 axes vectors in this plane
GEOMAPI_EXPORT
std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
#include "ModuleBase_ISelection.h"
+#include <StdSelect_BRepOwner.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <TopoDS.hxx>
+#include <BRep_Tool.hxx>
+#include <GeomAPI_Pnt.h>
+
//********************************************************************
void ModuleBase_ISelection::appendSelected(const QList<ModuleBase_ViewerPrs> theValues,
QList<ModuleBase_ViewerPrs>& theValuesTo)
}
return aSelectedPrs;
}
+
+//********************************************************************
+void ModuleBase_ISelection::filterPreselectionOnEqualPoints
+ (QList<ModuleBase_ViewerPrs>& theSelected)
+{
+ QList<ModuleBase_ViewerPrs> aCandidatesToRemove;
+ QList<ModuleBase_ViewerPrs>::const_iterator anIt = theSelected.begin(),
+ aLast = theSelected.end();
+ QList<ModuleBase_ViewerPrs>::const_iterator aSubIt;
+ for (; anIt != aLast; anIt++) {
+ aSubIt = anIt;
+ aSubIt++;
+ for (; aSubIt != aLast; aSubIt++) {
+ if (isEqualVertices(*anIt, *aSubIt)) {
+ aCandidatesToRemove.append(*aSubIt);
+ break;
+ }
+ }
+ }
+ QList<ModuleBase_ViewerPrs>::const_iterator aRemIt = aCandidatesToRemove.begin(),
+ aRemLast = aCandidatesToRemove.end();
+ for (; aRemIt != aRemLast; aRemIt++) {
+ theSelected.removeAll(*aRemIt);
+ }
+}
+
+bool ModuleBase_ISelection::isEqualVertices(const ModuleBase_ViewerPrs thePrs1,
+ const ModuleBase_ViewerPrs thePrs2)
+{
+ bool isEqual = false;
+ Handle(StdSelect_BRepOwner) anOwner1 = Handle(StdSelect_BRepOwner)::DownCast(thePrs1.owner());
+ Handle(StdSelect_BRepOwner) anOwner2 = Handle(StdSelect_BRepOwner)::DownCast(thePrs2.owner());
+
+ if (!anOwner1.IsNull() && anOwner1->HasShape() &&
+ !anOwner2.IsNull() && anOwner2->HasShape()) {
+ const TopoDS_Shape& aShape1 = anOwner1->Shape();
+ const TopoDS_Shape& aShape2 = anOwner2->Shape();
+ //TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
+ if (aShape1.ShapeType() == TopAbs_VERTEX &&
+ aShape2.ShapeType() == TopAbs_VERTEX) {
+ const TopoDS_Vertex& aVertex1 = TopoDS::Vertex(aShape1);
+ const TopoDS_Vertex& aVertex2 = TopoDS::Vertex(aShape2);
+ if (!aVertex1.IsNull() && !aVertex2.IsNull()) {
+ gp_Pnt aPoint1 = BRep_Tool::Pnt(aVertex1);
+ gp_Pnt aPoint2 = BRep_Tool::Pnt(aVertex2);
+
+ std::shared_ptr<GeomAPI_Pnt> aPnt1 = std::shared_ptr<GeomAPI_Pnt>
+ (new GeomAPI_Pnt(aPoint1.X(), aPoint1.Y(), aPoint1.Z()));
+ std::shared_ptr<GeomAPI_Pnt> aPnt2 = std::shared_ptr<GeomAPI_Pnt>
+ (new GeomAPI_Pnt(aPoint2.X(), aPoint2.Y(), aPoint2.Z()));
+ isEqual = aPnt1->isEqual(aPnt2);
+ }
+ }
+ }
+
+ return isEqual;
+}
//! \return a list of prs, where only object is not empty
static MODULEBASE_EXPORT QList<ModuleBase_ViewerPrs> getViewerPrs(
const QObjectPtrList& theObjects);
+
+ /// Removes selection items where owners have equal vertices. The first
+ /// owner with the qual vertex stays in the list.
+ static MODULEBASE_EXPORT void filterPreselectionOnEqualPoints
+ (QList<ModuleBase_ViewerPrs>& theSelected);
+private:
+ /// Returns true if the presentations have an owner with a vertex and these vertices are equal.
+ /// \param thePrs1 the first viewer selected presentation
+ /// \param thePrs2 the second viewer selected presentation
+ static bool isEqualVertices(const ModuleBase_ViewerPrs thePrs1,
+ const ModuleBase_ViewerPrs thePrs2);
};
#endif
//! Returns true if multiselection is enabled
virtual bool isMultiSelectionEnabled() const = 0;
+ //! Enable or disable draw mode in the viewer
+ virtual bool enableDrawMode(bool isEnabled) = 0;
+
//! Perfroms the fit all for the active view
virtual void fitAll() = 0;
if (myPreSelection.empty())
return;
+ ModuleBase_ISelection::filterPreselectionOnEqualPoints(myPreSelection);
+
ModuleBase_ModelWidget* aFilledWgt = 0;
ModuleBase_IPropertyPanel* aPropertyPanel = propertyPanel();
if (aPropertyPanel) {
{
if (mySelector)
return mySelector->viewer()->isSelectionEnabled();
+ return false;
}
//**********************************************
return false;
}
+//**********************************************
+bool NewGeom_SalomeViewer::enableDrawMode(bool isEnabled)
+{
+ // TODO: Has to be replaced when SALOME patch become avialable
+ if (mySelector)
+ return mySelector->viewer()->enableDrawMode(isEnabled);
+ return false;
+}
+
//**********************************************
void NewGeom_SalomeViewer::fitAll()
{
//! Returns true if multiselection is enabled
virtual bool isMultiSelectionEnabled() const;
+ //! Enable or disable draw mode in the viewer
+ virtual bool enableDrawMode(bool isEnabled);
+
//! Perfroms the fit all for the active view
virtual void fitAll();
ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
- myPreviousSelectionEnabled = true;//aViewer->isSelectionEnabled();
+ myPreviousDrawModeEnabled = true;//aViewer->isSelectionEnabled();
connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
if (!isNestedCreateOperation(getCurrentOperation()))
return;
- operationMgr()->onValidateOperation();
+
+ QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));//QIcon(":pictures/button_plus.png").pixmap(20,20)));
+ operationMgr()->onValidateOperation();
// we need change displayed state of the current operation feature
// if the feature is presentable, e.g. distance construction. It has no results, so workshop does
if (!isNestedCreateOperation(getCurrentOperation()))
return;
+
+ QApplication::restoreOverrideCursor();
+
// the method should be performed if the popup menu is called,
// the reset of the current widget should not happen
if (myIsPopupMenuActive)
ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
ModuleBase_IViewer* aViewer = aWorkshop->viewer();
- myPreviousSelectionEnabled = aViewer->isSelectionEnabled();
if (!aViewer->canDragByMouse())
return;
myIsDragging = true;
get2dPoint(theWnd, theEvent, myCurrentPoint);
myDragDone = false;
+ // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
+ myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
launchEditing();
if (aFeature.get() != NULL) {
std::shared_ptr<SketchPlugin_Feature> aSPFeature =
myIsDragging = true;
get2dPoint(theWnd, theEvent, myCurrentPoint);
myDragDone = false;
+ // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
+ myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
// This is necessary in order to finalize previous operation
QApplication::processEvents();
}
}
}
- aWorkshop->viewer()->enableSelection(myPreviousSelectionEnabled);
+ // TODO: Has to be uncommented when SALOME patch on draw mode become avialable
+ aWorkshop->viewer()->enableDrawMode(myPreviousDrawModeEnabled);
+ //aWorkshop->viewer()->enableSelection(myPreviousDrawModeEnabled);
myIsDragging = false;
}
// 2. the enable selection in the viewer should be temporary switched off in order to ignore
// mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
// deselected). This flag should be restored in the slot, processed the mouse release signal.
- ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
- aViewer->enableSelection(false);
+
+ // TODO: Has to be commented out when SALOME patch on draw mode become avialable
+ //ModuleBase_IViewer* aViewer = myModule->workshop()->viewer();
+ //aViewer->enableSelection(false);
ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
if (!aCurrentOperation)
void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
{
connectToPropertyPanel(true);
- if (isNestedCreateOperation(theOperation))
+ if (isNestedCreateOperation(theOperation) && myIsMouseOverWindow)
QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));//QIcon(":pictures/button_plus.png").pixmap(20,20)));
}
private:
PartSet_Module* myModule;
- bool myPreviousSelectionEnabled; // the previous selection enabled state in the viewer
+ bool myPreviousDrawModeEnabled; // the previous selection enabled state in the viewer
bool myIsDragging;
bool myDragDone;
bool myIsResetCurrentValue; /// the state that value in the property panel is reset
int shapesNbPoints(const ModuleBase_ISelection* theSelection)
{
QList<ModuleBase_ViewerPrs> aList = theSelection->getSelected(ModuleBase_ISelection::Viewer);
+ ModuleBase_ISelection::filterPreselectionOnEqualPoints(aList);
+
int aCount = 0;
foreach (ModuleBase_ViewerPrs aPrs, aList) {
const TopoDS_Shape& aShape = aPrs.shape();
bool XGUI_OperationMgr::canStopOperation(ModuleBase_Operation* theOperation)
{
//in case of nested (sketch) operation no confirmation needed
- if (isGrantedOperation(theOperation))
+ if (isGrantedOperation(theOperation->id()))
return true;
if (theOperation && theOperation->isModified()) {
QString aMessage = tr("%1 operation will be aborted.").arg(theOperation->id());
theOperation->resume();
}
-bool XGUI_OperationMgr::isGrantedOperation(ModuleBase_Operation* theOperation)
+bool XGUI_OperationMgr::isGrantedOperation(const QString& theId)
{
bool isGranted = false;
ModuleBase_Operation* aPreviousOperation = 0;
while (anIt.hasPrevious()) {
ModuleBase_Operation* anOp = anIt.previous();
- if (anOp == theOperation) {
+ if (anOp->id() == theId) {
if (anIt.hasPrevious())
aPreviousOperation = anIt.previous();
break;
}
}
if (aPreviousOperation)
- isGranted = aPreviousOperation->isGranted(theOperation->id());
+ isGranted = aPreviousOperation->isGranted(theId);
return isGranted;
}
ModuleBase_Operation* aCurrentOp = currentOperation();
if (aCurrentOp) {
bool aGranted = aCurrentOp->isGranted(theId) || isAdditionallyGranted;
- if (!aGranted) {
- if (canStopOperation(aCurrentOp)) {
+ // the started operation is granted for the current one,
+ // e.g. current - Sketch, started - Line
+ if (aGranted) {
+ aCanStart = true;
+ }
+ else {
+ if (!isGrantedOperation(theId)) {
+ // the operation is not granted in the current list of operations
+ // e.g. Edit Parameter when Sketch, Line in Sketch is active.
+ aCanStart = abortAllOperations();
+ }
+ else if (canStopOperation(aCurrentOp)) {
+ // the started operation is granted in the parrent operation,
+ // e.g. current - Line in Sketch, started Circle
if (myIsApplyEnabled && aCurrentOp->isModified())
aCurrentOp->commit();
else
/// Returns whether the parameter operation is granted in relation to the previous operation
/// in a stack of started operations. It is used in canStopOperation to avoid warning message
/// when granted operation is aborted, e.g. SketchLine in Sketch
- /// \param theOperation the started operation
+ /// \param theId id of the operation which is checked
/// \return boolean result
- bool isGrantedOperation(ModuleBase_Operation* theOperation);
+ bool isGrantedOperation(const QString& theId);
/// Sets the feature as a current in the document
/// \param theFeature a feature
activateWidget(NULL);
return;
}
- ModuleBase_ModelWidget* aNextWidget = 0;
QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end();
bool isFoundWidget = false;
activateWindow();
- for (; anIt != aLast && !aNextWidget; anIt++) {
+ for (; anIt != aLast; anIt++) {
if (isFoundWidget || !theWidget) {
if ((*anIt)->focusTo()) {
- aNextWidget = *anIt;
+ return;
}
}
isFoundWidget = (*anIt) == theWidget;
}
- // Normaly focusTo is enough to activate widget
- // here is a special case on mouse click in the viewer
- if(aNextWidget == NULL) {
- activateWidget(aNextWidget);
- }
+ activateWidget(NULL);
}
void XGUI_PropertyPanel::activateNextWidget()
}
}
+//***************************************
+bool XGUI_ViewerProxy::enableDrawMode(bool isEnabled)
+{
+ if (myWorkshop->isSalomeMode()) {
+ return myWorkshop->salomeConnector()->viewer()->enableDrawMode(isEnabled);
+ } else {
+ return myWorkshop->mainWindow()->viewer()->enableDrawMode(isEnabled);
+ }
+}
+
//***************************************
void XGUI_ViewerProxy::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
{
//! Returns true if multiselection is enabled
virtual bool isMultiSelectionEnabled() const;
+ //! Enable or disable draw mode in the viewer
+ virtual bool enableDrawMode(bool isEnabled);
+
//! Sets the view projection
/// \param theX the X projection value
/// \param theY the Y projection value