00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 #include <QtGui/QAction>
00032 #include <QtGui/QMouseEvent>
00033 
00034 #include <qnamespace.h>
00035 #include "qocc3dwidget.h"
00036 #include "commands/qocccmdline2pt.h"
00037 #include "qoccinternal.h"
00038 
00039 QoccDlgLine2Pt::QoccDlgLine2Pt( )
00040 {
00041 
00042 }
00043 
00044 QoccDlgLine2Pt::~QoccDlgLine2Pt( )
00045 {
00046 
00047 }
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 QoccCmdLine2Pt::QoccCmdLine2Pt( QAction* startingAction, QWidget* parent )
00056 :QoccCommand( startingAction, parent )
00057 {
00058         myParameter = Point1;
00059         myDocument = NULL;
00060         if ( myAction )
00061         {
00062                 myAction->setDisabled(true);
00063         }
00064 }
00065 
00066 QoccCmdLine2Pt::~QoccCmdLine2Pt( )
00067 {
00068         
00069         
00070         if (!myStart.IsNull())
00071         {
00072                 myDocument->RemovePresentation( myStart );
00073                 myStart.Nullify();
00074         }
00075 
00076         if (!myLine.IsNull())
00077         {
00078                 myDocument->RemovePresentation( myLine );
00079                 myLine.Nullify();
00080         }
00081 
00082         if ( myAction )
00083         {
00084                 myAction->setDisabled(false);
00085         }
00086 
00087 }
00088 
00089 void QoccCmdLine2Pt::clickEvent( Qocc3dWidget* widget, QMouseEvent* e )
00090 {
00091         Q_UNUSED(e)
00092         QoccController* vc = widget->getController();
00093         QoccDocument* doc = vc->getDocument();
00094         TopAbs_ShapeEnum lc;
00095         int doc_id = doc->id();
00096         double x = widget->x();
00097         double y = widget->y();
00098         double z = widget->z();
00099         gp_Dir dir = widget->getDirection();
00100 
00101         switch (myParameter)
00102         {
00103                 case Point1:
00104                         myDocument = doc;
00105                         myStartPoint = gp_Pnt(x, y, z);
00106                         myStart = qGeomApp->basicOps( doc_id )->MakePointXYZ( x, y, z );
00107                         doc->RegisterPresentation( myStart );
00108                         myIsDrawing = true;
00109                         myParameter = Point2;
00110                         break;
00111 
00112                 case Point2:
00113                         if (!myLine.IsNull())
00114                         {
00115                                 doc->RemovePresentation( myLine );
00116                                 myLine.Nullify();
00117                         }
00118                         doc->RemovePresentation( myStart );
00119                         myCurrentPoint = gp_Pnt (x, y, z);
00120                         double d = myStartPoint.Distance( myCurrentPoint );
00121                         if (d > 0.)
00122                         {
00123                                 bool hasLc = vc->hasLocalContext();
00124                                 if (hasLc) 
00125                                 {
00126                                         lc = vc->localContext();
00127                                         vc->clearLocalContext();
00128                                 }
00129 
00130                                 myEnd = qGeomApp->basicOps( doc_id )->MakePointXYZ( x, y, z );
00131 
00132                                 qGeomApp->curvesOps( doc_id )->StartOperation();
00133                                 Handle(GEOM_Object) theLine = qGeomApp->basicOps( doc_id )->MakeLineTwoPnt (myStart, myEnd);
00134                                 doc->RegisterPresentation( theLine );
00135                                 qGeomApp->curvesOps( doc_id )->FinishOperation();
00136                                 
00137                                 if (hasLc) 
00138                                 {
00139                                         vc->setLocalContext(lc);
00140                                         vc->update();
00141                                 }
00142 
00143                                 myStart.Nullify();
00144                                 myIsDrawing = false;
00145                                 myParameter = Point1;
00146                         }
00147                         break;
00148         }
00149 }
00150 
00151 void QoccCmdLine2Pt::moveEvent( Qocc3dWidget* widget, QMouseEvent* e )
00152 {
00153         Q_UNUSED(e)
00154         QoccDocument* doc = widget->getController()->getDocument();
00155         int doc_id = doc->id();
00156         double x = widget->x();
00157         double y = widget->y();
00158         double z = widget->z();
00159 
00160         switch (myParameter)
00161         {
00162                 case Point1:
00163                         break;
00164 
00165                 case Point2:
00166                         if (!myLine.IsNull())
00167                         {
00168                                 doc->RemovePresentation( myLine );
00169                                 myLine.Nullify();
00170                         }
00171                         myCurrentPoint = gp_Pnt (x, y, z);
00172                         double d = myStartPoint.Distance( myCurrentPoint );
00173                         if (d > 0.)
00174                         {
00175                                 myEnd = qGeomApp->basicOps( doc_id )->MakePointXYZ( x, y, z );
00176                                 myLine = qGeomApp->basicOps( doc_id )->MakeLineTwoPnt (myStart, myEnd);
00177                                 doc->RegisterPresentation( myLine );
00178                         }
00179                         break;
00180         }
00181 }