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/qocccmdcircle2pt.h"
00037 #include "qoccinternal.h"
00038 
00039 QoccDlgCircle2Pt::QoccDlgCircle2Pt( )
00040 {
00041 
00042 }
00043 
00044 QoccDlgCircle2Pt::~QoccDlgCircle2Pt( )
00045 {
00046 }
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 QoccCmdCircle2Pt::QoccCmdCircle2Pt( QAction* startingAction, QWidget* parent )
00055 :QoccCommand( startingAction, parent )
00056 {
00057         myParameter = Centre;
00058         myDocument = NULL;
00059         if ( myAction )
00060         {
00061                 myAction->setDisabled(true);
00062         }
00063 }
00064 
00065 QoccCmdCircle2Pt::~QoccCmdCircle2Pt( )
00066 {
00067         
00068         
00069         if (!myCentre.IsNull())
00070         {
00071                 myDocument->RemovePresentation( myCentre );
00072                 myCentre.Nullify();
00073         }
00074 
00075         if (!myCircle.IsNull())
00076         {
00077                 myDocument->RemovePresentation( myCircle );
00078                 myCircle.Nullify();
00079         }
00080 
00081         if ( myAction )
00082         {
00083                 myAction->setDisabled(false);
00084         }
00085 }
00086 
00087 void QoccCmdCircle2Pt::clickEvent( Qocc3dWidget* widget, QMouseEvent* e )
00088 {
00089         Q_UNUSED(e)
00090         QoccController* vc = widget->getController();
00091         QoccDocument* doc = vc->getDocument();
00092         TopAbs_ShapeEnum lc;
00093         int doc_id = doc->id();
00094         double x = widget->x();
00095         double y = widget->y();
00096         double z = widget->z();
00097         gp_Dir dir = widget->getDirection();
00098 
00099         switch (myParameter)
00100         {
00101                 case Centre:
00102                         myDocument = doc;
00103                         myStartPoint = gp_Pnt(x, y, z);
00104                         myVector = qGeomApp->basicOps( doc_id )->MakeVectorDXDYDZ( dir.X(), dir.Y(), dir.Z() );
00105                         myCentre = qGeomApp->basicOps( doc_id )->MakePointXYZ( x, y, z );
00106                         doc->RegisterPresentation( myCentre );
00107                         myIsDrawing = true;
00108                         myParameter = Radius;
00109                         break;
00110 
00111                 case Radius:
00112                         if (!myCircle.IsNull())
00113                         {
00114                                 doc->RemovePresentation( myCircle );
00115                                 myCircle.Nullify();
00116                         }
00117                         myCurrentPoint = gp_Pnt (x, y, z);
00118                         myRadius = myStartPoint.Distance( myCurrentPoint );
00119 
00120                         bool hasLc = vc->hasLocalContext();
00121                         if (hasLc) 
00122                         {
00123                                 lc = vc->localContext();
00124                                 vc->clearLocalContext();
00125                         }
00126                         if (myRadius > 0. )
00127                         {
00128                                 qGeomApp->curvesOps( doc_id )->StartOperation();
00129                                 Handle(GEOM_Object) theCircle = qGeomApp->curvesOps( doc_id )->MakeCirclePntVecR(myCentre, myVector, myRadius);
00130                                 doc->RegisterPresentation( theCircle );
00131                                 qGeomApp->curvesOps( doc_id )->FinishOperation();
00132                         }
00133 
00134                         if (hasLc) 
00135                         {
00136                                 vc->setLocalContext(lc);
00137                                 vc->update();
00138                         }
00139 
00140                         doc->RemovePresentation( myCentre );
00141                         myCentre.Nullify();
00142 
00143                         myIsDrawing = false;
00144                         myParameter = Centre;
00145                         break;
00146         }
00147 }
00148 
00149 void QoccCmdCircle2Pt::moveEvent( Qocc3dWidget* widget, QMouseEvent* e )
00150 {
00151         Q_UNUSED(e)
00152         QoccDocument* doc = widget->getController()->getDocument();
00153         int doc_id = doc->id();
00154         double x = widget->x();
00155         double y = widget->y();
00156         double z = widget->z();
00157 
00158         switch (myParameter)
00159         {
00160                 case Centre:
00161                         break;
00162 
00163                 case Radius:
00164                         if (!myCircle.IsNull())
00165                         {
00166                                 doc->RemovePresentation( myCircle );
00167                                 myCircle.Nullify();
00168                         }
00169                         myCurrentPoint = gp_Pnt (x, y, z);
00170                         myRadius = myStartPoint.Distance( myCurrentPoint );
00171                         if (myRadius > 0.)
00172                         {
00173                                 myCircle = qGeomApp->curvesOps( doc_id )->MakeCirclePntVecR(myCentre, myVector, myRadius);
00174                                 doc->RegisterPresentation( myCircle );
00175                         }
00176                         break;
00177         }
00178 }