1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

Compare commits

...

1 Commits

Author SHA1 Message Date
mkrylova
163e58793e 0031549: Draw Harness, ViewerTest - add interactive polygon definition mode to vselect command
Has been added an option to interactive polygonal selection by
- addition new option "-polygonal" to vselect command
- addition activation polygonal selection mode in ViewerTest_ViewerCommands
- addition new AIS_MouseGesture
- addition new function in AIS_ViewController to set new AIS_MouseGesture
- addition Boolean variable in ViewerTest_EventManager to enable/disable polygonal selection
- editing functions in ViewerTest_EventManager for manipulation with selection
2020-06-16 15:16:34 +03:00
6 changed files with 77 additions and 12 deletions

View File

@@ -25,6 +25,8 @@ enum AIS_MouseGesture
//! press button to start, move mouse to define rectangle, release to finish //! press button to start, move mouse to define rectangle, release to finish
AIS_MouseGesture_SelectLasso, //!< polygonal selection; AIS_MouseGesture_SelectLasso, //!< polygonal selection;
//! press button to start, move mouse to define polygonal path, release to finish //! press button to start, move mouse to define polygonal path, release to finish
AIS_MouseGesture_SelectPolygonal, //!< polygonal selection;
//! press buttons to define the vertices of the polygon, click on the first vertex or Esc to finish
// //
AIS_MouseGesture_Zoom, //!< view zoom gesture; AIS_MouseGesture_Zoom, //!< view zoom gesture;
//! move mouse left to zoom-out, and to the right to zoom-in //! move mouse left to zoom-out, and to the right to zoom-in

View File

@@ -149,6 +149,15 @@ AIS_ViewController::~AIS_ViewController()
// //
} }
// =======================================================================
// function : ActivatePolygonalSelection
// purpose :
// =======================================================================
void AIS_ViewController::ActivatePolygonalSelection()
{
myMouseActiveGesture = AIS_MouseGesture_SelectPolygonal;
}
// ======================================================================= // =======================================================================
// function : ResetViewInput // function : ResetViewInput
// purpose : // purpose :

View File

@@ -598,6 +598,8 @@ public:
const Handle(V3d_View)& theView, const Handle(V3d_View)& theView,
const gp_Trsf& thePose, const gp_Trsf& thePose,
const Standard_Boolean theToHighlight); const Standard_Boolean theToHighlight);
//! Activate polygonal selection mode.
Standard_EXPORT void ActivatePolygonalSelection();
protected: protected:

View File

@@ -45,7 +45,8 @@ ViewerTest_EventManager::ViewerTest_EventManager (const Handle(V3d_View)&
const Handle(AIS_InteractiveContext)& theCtx) const Handle(AIS_InteractiveContext)& theCtx)
: myCtx (theCtx), : myCtx (theCtx),
myView (theView), myView (theView),
myToPickPnt (Standard_False) myToPickPnt (Standard_False),
myToSelectPolygon (Standard_False)
{ {
myViewAnimation = GlobalViewAnimation(); myViewAnimation = GlobalViewAnimation();
} }
@@ -64,30 +65,63 @@ ViewerTest_EventManager::~ViewerTest_EventManager()
} }
} }
//=======================================================================
//function : PolygonalSelection
//purpose :
//=======================================================================
void ViewerTest_EventManager::SelectPolygon()
{
ActivatePolygonalSelection();
myToSelectPolygon = Standard_True;
}
//======================================================================= //=======================================================================
//function : UpdateMouseButtons //function : UpdateMouseButtons
//purpose : //purpose :
//======================================================================= //=======================================================================
bool ViewerTest_EventManager::UpdateMouseButtons (const Graphic3d_Vec2i& thePoint, bool ViewerTest_EventManager::UpdateMouseButtons(const Graphic3d_Vec2i& thePoint,
Aspect_VKeyMouse theButtons, Aspect_VKeyMouse theButtons,
Aspect_VKeyFlags theModifiers, Aspect_VKeyFlags theModifiers,
bool theIsEmulated) bool theIsEmulated)
{ {
SetAllowRotation (!ViewerTest_V3dView::IsCurrentViewIn2DMode()); SetAllowRotation(!ViewerTest_V3dView::IsCurrentViewIn2DMode());
if (theButtons == Aspect_VKeyMouse_LeftButton) if (theButtons == Aspect_VKeyMouse_LeftButton)
{ {
if (myToPickPnt && (theModifiers & Aspect_VKeyFlags_CTRL) != 0) if (myToPickPnt && (theModifiers & Aspect_VKeyFlags_CTRL) != 0)
{ {
Graphic3d_Vec3d anXYZ; Graphic3d_Vec3d anXYZ;
myView->Convert (thePoint.x(), thePoint.y(), anXYZ.x(), anXYZ.y(), anXYZ.z()); myView->Convert(thePoint.x(), thePoint.y(), anXYZ.x(), anXYZ.y(), anXYZ.z());
Draw::Set (myPickPntArgVec[0].ToCString(), anXYZ.x()); Draw::Set(myPickPntArgVec[0].ToCString(), anXYZ.x());
Draw::Set (myPickPntArgVec[1].ToCString(), anXYZ.y()); Draw::Set(myPickPntArgVec[1].ToCString(), anXYZ.y());
Draw::Set (myPickPntArgVec[2].ToCString(), anXYZ.z()); Draw::Set(myPickPntArgVec[2].ToCString(), anXYZ.z());
myToPickPnt = false; myToPickPnt = false;
} }
} }
if (myToSelectPolygon)
{
if ((theButtons & Aspect_VKeyMouse_LeftButton) == Aspect_VKeyMouse_LeftButton)
{
if (!myUI.Selection.Points.IsEmpty())
{
if (myUI.Selection.Points.First() == thePoint)
{
myUI.Selection.ToApplyTool = true;
myToSelectPolygon = Standard_False;
}
}
UpdatePolySelection(thePoint, true);
FlushViewEvents(myCtx, myView, true);
return true;
}
else if (((theButtons & Aspect_VKeyMouse_RightButton) == Aspect_VKeyMouse_RightButton)
&& (!myUI.Selection.Points.IsEmpty()))
{
myUI.Selection.Points.Remove(myUI.Selection.Points.Size());
}
}
return AIS_ViewController::UpdateMouseButtons (thePoint, theButtons, theModifiers, theIsEmulated); return AIS_ViewController::UpdateMouseButtons (thePoint, theButtons, theModifiers, theIsEmulated);
} }
@@ -338,6 +372,13 @@ void ViewerTest_EventManager::ProcessKeyPress (Aspect_VKey theKey)
{ {
Draw_Interprete (ViewerTest_EventManager::ToExitOnCloseView() ? "exit" : "vclose"); Draw_Interprete (ViewerTest_EventManager::ToExitOnCloseView() ? "exit" : "vclose");
} }
if (myToSelectPolygon)
{
myToSelectPolygon = false;
myUI.Selection.Points.Clear();
myView->Redraw();
myView->Invalidate();
}
} }
} }

View File

@@ -94,6 +94,8 @@ public:
//! Handle KeyPress event. //! Handle KeyPress event.
Standard_EXPORT void ProcessKeyPress (Aspect_VKey theKey); Standard_EXPORT void ProcessKeyPress (Aspect_VKey theKey);
Standard_EXPORT void SelectPolygon ();
private: private:
Handle(AIS_InteractiveContext) myCtx; Handle(AIS_InteractiveContext) myCtx;
@@ -101,7 +103,7 @@ private:
TCollection_AsciiString myPickPntArgVec[3]; TCollection_AsciiString myPickPntArgVec[3];
Standard_Boolean myToPickPnt; Standard_Boolean myToPickPnt;
Standard_Boolean myToSelectPolygon;
}; };
#endif // _ViewerTest_EventManager_HeaderFile #endif // _ViewerTest_EventManager_HeaderFile

View File

@@ -7615,7 +7615,7 @@ static Standard_Integer VSelect (Draw_Interpretor& ,
} }
NCollection_Sequence<Graphic3d_Vec2i> aPnts; NCollection_Sequence<Graphic3d_Vec2i> aPnts;
bool isShiftSelection = false, toAllowOverlap = false; bool isShiftSelection = false, toAllowOverlap = false, toSelectPolygon = false;
for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter) for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
{ {
TCollection_AsciiString anArg (theArgVec[anArgIter]); TCollection_AsciiString anArg (theArgVec[anArgIter]);
@@ -7629,6 +7629,11 @@ static Standard_Integer VSelect (Draw_Interpretor& ,
++anArgIter; ++anArgIter;
} }
} }
else if (anArg == "-polygonal")
{
std::cout << "Polygonal Selection is activated" << std::endl;
toSelectPolygon = true;
}
else if (anArgIter + 1 < theNbArgs else if (anArgIter + 1 < theNbArgs
&& anArg.IsIntegerValue() && anArg.IsIntegerValue()
&& TCollection_AsciiString (theArgVec[anArgIter + 1]).IsIntegerValue()) && TCollection_AsciiString (theArgVec[anArgIter + 1]).IsIntegerValue())
@@ -7654,6 +7659,10 @@ static Standard_Integer VSelect (Draw_Interpretor& ,
} }
Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager(); Handle(ViewerTest_EventManager) aCurrentEventManager = ViewerTest::CurrentEventManager();
if (toSelectPolygon)
{
aCurrentEventManager->SelectPolygon();
}
if (aPnts.IsEmpty()) if (aPnts.IsEmpty())
{ {
if (isShiftSelection) if (isShiftSelection)