#include <GeometryGUI.h>
#include "GeometryGUI_Operations.h"
+#include <SUIT_Session.h>
#include <SUIT_Desktop.h>
#include <SUIT_ViewWindow.h>
#include <OCCViewer_ViewModel.h>
#include <OCCViewer_ViewManager.h>
+#include <OCCViewer_ViewWindow.h>
+#include <OCCViewer_ViewPort3d.h>
#include <SalomeApp_Study.h>
#include <SalomeApp_Application.h>
#include <TopoDS_Shape.hxx>
+#include <TopoDS.hxx>
+#include <BRep_Tool.hxx>
+#include <ProjLib.hxx>
+#include <ElSLib.hxx>
+
+#include <QMouseEvent>
#include "EntityGUI_SketcherDlg.h" // Sketcher
#include "EntityGUI_3DSketcherDlg.h" // Sketcher
return true;
}
+//=================================================================================
+// function : 0nMousePress()
+// purpose : [static] manage mouse events
+//=================================================================================
+bool EntityGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
+{
+ MESSAGE("EntityGUI::OnMousePress")
+ QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
+
+ // Create Point dialog, OCC viewer
+ if ( aDlg && ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_SketcherDlg" ) == 0 ) &&
+ theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() &&
+ pe->modifiers() != Qt::ControlModifier ) {
+ MESSAGE("Premier if ok!")
+ EntityGUI_SketcherDlg* aPntDlg = (EntityGUI_SketcherDlg*) aDlg;
+ if ( aPntDlg->acceptMouseEvent() ) {
+ OCCViewer_Viewer* anOCCViewer =
+ ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer();
+ Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
+
+ gp_Pnt aPnt;
+
+ ic->InitSelected();
+ if ( pe->modifiers() == Qt::ShiftModifier )
+ ic->ShiftSelect(); // Append selection
+ else
+ ic->Select(); // New selection
+
+ ic->InitSelected();
+ if ( ic->MoreSelected() ) {
+ TopoDS_Shape aShape = ic->SelectedShape();
+ if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
+ aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
+ }
+ else {
+ OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
+ aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
+ }
+
+ Qt::KeyboardModifiers modifiers = pe->modifiers();
+ aPntDlg->OnPointSelected( modifiers, aPnt ); // "feed" the point to point construction dialog
+ } // acceptMouseEvent()
+ }
+ return false;
+}
+
+//=======================================================================
+// function : ConvertClickToPoint()
+// purpose : Returns the point clicked in 3D view
+//=======================================================================
+gp_Pnt EntityGUI::ConvertClickToPoint( int x, int y, Handle(V3d_View) aView )
+{
+ V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
+ aView->Eye( XEye, YEye, ZEye );
+
+ aView->At( XAt, YAt, ZAt );
+ gp_Pnt EyePoint( XEye, YEye, ZEye );
+ gp_Pnt AtPoint( XAt, YAt, ZAt );
+
+ gp_Vec EyeVector( EyePoint, AtPoint );
+ gp_Dir EyeDir( EyeVector );
+
+ gp_Pln PlaneOfTheView = gp_Pln( AtPoint, EyeDir );
+ Standard_Real X, Y, Z;
+ aView->Convert( x, y, X, Y, Z );
+ gp_Pnt ConvertedPoint( X, Y, Z );
+
+ gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project( PlaneOfTheView, ConvertedPoint );
+ gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView );
+ return ResultPoint;
+}
//=====================================================================================
// function : DisplaySimulationShape()
//=====================================================================================
void EntityGUI::DisplaySimulationShape( const TopoDS_Shape& S1, const TopoDS_Shape& S2 )
{
+ MESSAGE("EntityGUI::DisplaySimulationShape")
SalomeApp_Application* app = getGeometryGUI()->getApp();
if ( !app ) return;
//==================================================================================
void EntityGUI::EraseSimulationShape()
{
+ MESSAGE("EntityGUI::EraseSimulationShape")
SalomeApp_Application* app = getGeometryGUI()->getApp();
if ( !app ) return;
#include <SALOMEDSClient.hxx>
#include <AIS_Shape.hxx>
+#include <V3d_View.hxx>
class TopoDS_Shape;
+
//=================================================================================
// class : EntityGUI
// purpose :
~EntityGUI();
bool OnGUIEvent( int, SUIT_Desktop* );
+ bool OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow );
+
+ gp_Pnt ConvertClickToPoint( int x, int y, Handle(V3d_View) aView );
void DisplaySimulationShape( const TopoDS_Shape&, const TopoDS_Shape& );
void EraseSimulationShape();
// AIS shape used only during topo/geom simulations
Handle(AIS_Shape) mySimulationShape1;
Handle(AIS_Shape) mySimulationShape2;
+
};
#endif // ENTITYGUI_H
//=================================================================================
void EntityGUI_SketcherDlg::SelectionIntoArgument()
{
+ MESSAGE("EntityGUI_SketcherDlg::SelectionIntoArgument")
myEditCurrentArgument->setText( "" );
double tmpX = myX;
double tmpY = myY;
aSelMgr->selectedObjects(aSelList);
int nbSel = aSelList.Extent();
+ MESSAGE("NbSel = "<<nbSel)
+ if (nbSel == 0){
+ myX=tmpX;
+ myY=tmpY;
+ }
if (nbSel == 1 && myEditCurrentArgument == Group1Sel->LineEdit1) {
GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
if ( !CORBA::is_nil(aSelectedObject) ) {
//=================================================================================
void EntityGUI_SketcherDlg::closeEvent( QCloseEvent* e )
{
+ MESSAGE("EntityGUI_SketcherDlg::closeEvent")
//myGeometryGUI->SetState( -1 );
disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
myGeometryGUI->getApp()->updateActions();
QDialog::closeEvent( e );
}
+//rnc TODO
+//=================================================================================
+// function : OnPointSelected
+// purpose :
+//=================================================================================
+void EntityGUI_SketcherDlg::OnPointSelected(Qt::KeyboardModifiers modifiers, const gp_Pnt& thePnt)
+{
+ MESSAGE("EntityGUI_SketcherDlg::OnPointSelected")
+ switch (getPnt2ConstructorId()){
+ case 1:
+ Group2Spin->SpinBox_DX->setValue( thePnt.X() );
+ Group2Spin->SpinBox_DY->setValue( thePnt.Y() );
+ break;
+ case 0:
+ Group3Spin->SpinBox_DX->setValue( thePnt.X() );
+ Group3Spin->SpinBox_DY->setValue( thePnt.Y() );
+ break;
+ case 2:
+ if (modifiers == Qt::MetaModifier){ // Select center with Meta key
+ Group4Spin->SpinBox_DX->setValue( thePnt.X() );
+ Group4Spin->SpinBox_DY->setValue( thePnt.Y() );
+ }
+ else{ // The select end point
+ Group4Spin->SpinBox_DZ->setValue( thePnt.X() );
+ Group4Spin->SpinBox_DS->setValue( thePnt.Y() );
+ }
+ break;
+ }
+}
//=================================================================================
// function : ValueChangedInSpinBox()
//=================================================================================
void EntityGUI_SketcherDlg::ValueChangedInSpinBox( double newValue )
{
+ MESSAGE("EntityGUI_SketcherDlg::ValueChangedInSpinBox")
QObject* send = (QObject*)sender();
- Standard_Real vx, vy, vz, vs, minRad;
- vx = vy = vz = vs = minRad =0.0;
+ Standard_Real vx, vy, vz, vs, minRad, dx, dy;
+ vx = vy = vz = vs = minRad = dx = dy = 0.0;
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
vy = Group3Spin->SpinBox_DY->value(); vyStr = Group3Spin->SpinBox_DY->text();
vz = Group3Spin->SpinBox_DZ->value();
if ( (mySketchType == PT_REL_RADIUS || mySketchType == PT_ABS_RADIUS) && (vx != 0 || vy != 0) ) {
- minRad = 0.5 * Sqrt(vx * vx + vy * vy); //Computation of the minimum acceptable radius for the arc calculation
+ if (mySketchType == PT_ABS_RADIUS){
+ dx = vx - myLastX1;
+ dy = vy - myLastY1;
+ }
+ else{
+ dx = vx;
+ dy = vy;
+ }
+ minRad = 0.5 * Sqrt(dx * dx + dy * dy); //Computation of the minimum acceptable radius for the arc calculation
if (aPrecision >= 0) // 'f' format in the QString
- LastDecimal = aPrecision;
+ LastDecimal = aPrecision;
else // 'g' format in the Qstring
- LastDecimal = qAbs( aPrecision ) - ceil( log10(minRad) );
+ LastDecimal = qAbs( aPrecision ) - ceil( log10(minRad) );
minRad = ceil(pow(10,LastDecimal) * minRad) / pow(10,LastDecimal); // Rounded up at the last allowed decimal place
if ( Abs(vz) < minRad){
- if (vz < 0.0)
- Group3Spin->SpinBox_DZ->setValue( - minRad );
- else
- Group3Spin->SpinBox_DZ->setValue( minRad );
+ if (vz < 0.0)
+ Group3Spin->SpinBox_DZ->setValue( - minRad );
+ else
+ Group3Spin->SpinBox_DZ->setValue( minRad );
}
}
vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
vx = Group3Spin->SpinBox_DX->value(); vxStr = Group3Spin->SpinBox_DX->text();
vy = newValue; vyStr = newValueStr;
vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
- if ( (mySketchType == PT_REL_RADIUS || mySketchType == PT_ABS_RADIUS) && (vx != 0 || vy != 0)){
- minRad = 0.5 * Sqrt(vx * vx + vy * vy); //Computation of the minimum acceptable radius for the arc calculation
+ if ( (mySketchType == PT_REL_RADIUS || mySketchType == PT_ABS_RADIUS) && (vx != 0 || vy != 0)){
+ if (mySketchType == PT_ABS_RADIUS){
+ dx = vx - myLastX1;
+ dy = vy - myLastY1;
+ }
+ else{
+ dx = vx;
+ dy = vy;
+ }
+ minRad = 0.5 * Sqrt(dx * dx + dy * dy); //Computation of the minimum acceptable radius for the arc calculation
if (aPrecision >= 0) // 'f' format in the QString
- LastDecimal = aPrecision;
+ LastDecimal = aPrecision;
else // 'g' format in the QString
- LastDecimal = qAbs( aPrecision ) - ceil( log10(minRad) );
- minRad = ceil(pow(10,LastDecimal) * minRad) / pow(10,LastDecimal); // Rounded up at the last allowed decimal place
+ LastDecimal = qAbs( aPrecision ) - ceil( log10(minRad) );
+ minRad = ceil(pow(10,LastDecimal) * minRad) / pow(10,LastDecimal); // Rounded up at the last allowed decimal place
if ( Abs(vz) < minRad){
- if (vz < 0.0)
- Group3Spin->SpinBox_DZ->setValue( - minRad );
- else
- Group3Spin->SpinBox_DZ->setValue( minRad );
+ if (vz < 0.0)
+ Group3Spin->SpinBox_DZ->setValue( - minRad );
+ else
+ Group3Spin->SpinBox_DZ->setValue( minRad );
}
}
vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
}
}
+//rnc TODO
+//=================================================================================
+// function : getPnt1ConstructorId()
+// purpose :
+//=================================================================================
+int EntityGUI_SketcherDlg::getPnt1ConstructorId() const
+{
+ int buttonId = GroupPt->ButtonGroup->checkedId();
+ MESSAGE("buttonId = "<<buttonId)
+ return buttonId;
+}
+
+//=================================================================================
+// function : getPnt2ConstructorId()
+// purpose :
+//=================================================================================
+int EntityGUI_SketcherDlg::getPnt2ConstructorId() const
+{
+ int buttonId = GroupPt2->ButtonGroup->checkedId();
+ MESSAGE("buttonId = "<<buttonId)
+ return buttonId;
+}
+
//=================================================================================
// function : GetActiveLocalCS()
// purpose : Get Working plane
~EntityGUI_SketcherDlg();
bool eventFilter (QObject* object, QEvent* event);
+
+ bool acceptMouseEvent() const { return ( getPnt1ConstructorId() == 1 ); } //accept mouse event only on absolute selection mode
+ void OnPointSelected( Qt::KeyboardModifiers, const gp_Pnt& ); // called by EntityGUI::OnMousePress()
protected:
void initSpinBox( SalomeApp_DoubleSpinBox*,
bool createShapes( GEOM::GEOM_Object_ptr,
TopoDS_Shape&,
TopoDS_Shape& );
+ int getPnt1ConstructorId() const;
+ int getPnt2ConstructorId() const;
private:
int myConstructorId;
QStringList myUndoParameters;
Standard_Real myX, myY, myDX, myDY;
- Standard_Real myXc, myYc, myDXc, myDYc;
+ Standard_Real myXc, myYc, myDXc, myDYc;
Standard_Real myLength, myAngle, myRadius;
Standard_Real myLastX1, myLastY1;
Standard_Real myLastX2, myLastY2;
QString myXStr, myYStr, myDXStr, myDYStr;
- QString myXcStr, myYcStr, myDXcStr, myDYcStr;
+ QString myXcStr, myYcStr, myDXcStr, myDYcStr;
QString myLengthStr, myAngleStr, myRadiusStr;
QString myLastX1Str, myLastY1Str;
QString myLastX2Str, myLastY2Str;
EntityGUI_3Spin1Check* Group3Spin;
EntityGUI_4Spin1Check* Group4Spin;
- QLabel* myErrLabel;
+ QLabel* myErrLabel;
QGroupBox* GroupBox1;
QComboBox* ComboBox1;
QList<gp_Ax3> myLCSList;
- int myCheckFlag;
+ int myCheckFlag;
+
+ TopAbs_ShapeEnum myNeedType;
private:
enum SketchState { FIRST_POINT, NEXT_POINT };