qocccmdcircle2pt.cpp

Go to the documentation of this file.
00001 /************************************************************************************
00002 **
00003 ** This file is part of the QtOPENCASCADE Toolkit.
00004 **
00005 ** Copyright (C) 2006, 2007, 2008 QtOCC Team Members
00006 **               Peter Dolbey, Marc Britten, Stephane Routelous
00007 **               Stefan Boeykens, Pawel Dobrolowski, Walter Steffe
00008 **               Álvaro Castro Castilla, Dirk Burski, Fotis Sioutis
00009 **
00010 ** This library is free software; you can redistribute it and/or
00011 ** modify it under the terms of the GNU Lesser General Public
00012 ** License as published by the Free Software Foundation; either
00013 ** version 2.1 of the License, or (at your option) any later version.
00014 **
00015 ** This library is distributed in the hope that it will be useful,
00016 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 ** Lesser General Public License for more details.
00019 **
00020 ** You should have received a copy of the GNU Lesser General Public
00021 ** License along with this library; if not, write to the Free Software
00022 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00023 **
00024 ***********************************************************************************/
00025 
00026 /*!
00027 \class  QoccCircle2ptDlg
00028 \brief  This class provides the keyboard entry for the circle-centre command
00029 \author Peter C. Dolbey
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 \class  QoccCmdCircle2Pt
00050 \brief  This class provides the interactive entry for the circle centre-radius command
00051 \author Peter C. Dolbey
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         // Clean up on Cancel
00068         // The order of removes is important
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 }

Generated on Sat Feb 23 21:22:15 2008 for QtGEOM by  doxygen 1.4.7