qocccmdline2pt.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 line 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/qocccmdline2pt.h"
00037 #include "qoccinternal.h"
00038 
00039 QoccDlgLine2Pt::QoccDlgLine2Pt( )
00040 {
00041 
00042 }
00043 
00044 QoccDlgLine2Pt::~QoccDlgLine2Pt( )
00045 {
00046 
00047 }
00048 
00049 /*!
00050 \class  QoccCmdLine2Pt
00051 \brief  This class provides the interactive entry for the 2 point line command
00052 \author Peter C. Dolbey
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         // Clean up on Cancel
00069         // The order of removes is important
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 }

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