00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "a2dprec.h"
00012
00013 #ifdef __BORLANDC__
00014 #pragma hdrstop
00015 #endif
00016
00017 #ifndef WX_PRECOMP
00018 #include "wx/wx.h"
00019 #endif
00020
00021 #include "wx/editor/sttool2.h"
00022
00023
00024 IMPLEMENT_CLASS(a2dZoomFast,a2dStTool)
00025 IMPLEMENT_CLASS(a2dFastSelect,a2dStTool)
00026 IMPLEMENT_CLASS(a2dFastSelect2,a2dStTool)
00027 IMPLEMENT_CLASS(a2dFastDragMultiTool, a2dStTool )
00028 IMPLEMENT_CLASS(a2dFastCopyMultiTool, a2dFastDragMultiTool )
00029 IMPLEMENT_CLASS(a2dStDrawToolFast, a2dStDrawTool)
00030
00031 const a2dCommandId a2dZoomFast::COMID_PushTool_ZoomFast( wxT("PushTool_ZoomFast") );
00032 const a2dCommandId a2dFastSelect::COMID_PushTool_FastSelect( wxT("PushTool_FastSelect") );
00033 const a2dCommandId a2dFastSelect2::COMID_PushTool_FastSelect2( wxT("PushTool_FastDeSelect") );
00034 const a2dCommandId a2dFastDragMultiTool::COMID_PushTool_FastDragMulti( wxT("PushTool_FastDragMulti") );
00035 const a2dCommandId a2dFastCopyMultiTool::COMID_PushTool_FastCopyMulti( wxT("PushTool_FastCopyMulti") );
00036 const a2dCommandId a2dDrawRectangleToolFast::COMID_PushTool_DrawRectangleFast( wxT("PushTool_DrawRectangleFast") );
00037 const a2dCommandId a2dDrawCircleToolFast::COMID_PushTool_DrawCircleFast( wxT("PushTool_DrawCircleFast") );
00038 const a2dCommandId a2dDrawPolygonLToolFast::COMID_PushTool_DrawPolygonLFast( wxT("PushTool_DrawPolygonLFast") );
00039 const a2dCommandId a2dDrawPolygonLToolFast::COMID_PushTool_DrawPolygonLFast_Splined( wxT("PushTool_DrawPolygonLFast_Splined") );
00040 const a2dCommandId a2dDrawPolylineLToolFast::COMID_PushTool_DrawPolylineLFast( wxT("PushTool_DrawPolylineLFast") );
00041 const a2dCommandId a2dDrawPolylineLToolFast::COMID_PushTool_DrawPolylineLFast_Splined( wxT("PushTool_DrawPolylineLFast_Splined") );
00042
00043
00044
00045
00046
00047
00048 A2D_BEGIN_EVENT_TABLE(a2dStDrawToolFast, a2dStDrawTool)
00049 A2D_END_EVENT_TABLE()
00050
00051 a2dStDrawToolFast::a2dStDrawToolFast(a2dStToolContr* controller):a2dStDrawTool(controller)
00052 {
00053
00054
00055 m_stroke = a2dStroke(*wxBLACK,0);
00056 m_fill = a2dFill(*wxRED);
00057 m_AllowModifyTemplate = true;
00058 }
00059
00060 a2dStDrawToolFast::~a2dStDrawToolFast()
00061 {
00062 }
00063
00064 bool a2dStDrawToolFast::CreateToolObjects()
00065 {
00066 a2dStTool::CreateToolObjects();
00067
00068
00069 m_canvasobject = m_original->TClone( clone_members | clone_childs | clone_seteditcopy | clone_setoriginal );
00070 GetCanvasView()->AddOverlayObject( m_canvasobject );
00071 GetCanvasView()->SetOverlayDrawStyle( RenderLAYERED );
00072 if ( GetCanvasView()->GetDrawer2D()->HasAlpha() || GetCanvasView()->GetTrippleBuf() )
00073 {
00074 m_canvasobject->SetFill( a2dFill( wxColour( 66, 159, 235, 50 ) ) );
00075 m_canvasobject->SetStroke( a2dStroke( wxColour( 66, 159, 235, 165 ), 2, a2dSTROKE_LONG_DASH) );
00076 }
00077 else
00078 {
00079 m_canvasobject->SetFill( *a2dTRANSPARENT_FILL );
00080 m_canvasobject->SetStroke( m_stroke );
00081
00082 }
00083
00084 m_canvasobject->SetSelected( false );
00085
00086 a2dCanvasObject::SetIgnoreAllSetpending( true );
00087 AddCurrent( m_original );
00088 m_original->SetSnapTo( true );
00089 m_original->SetVisible( m_renderOriginal );
00090 m_original->SetVisible( false );
00091 a2dCanvasObject::SetIgnoreAllSetpending( false );
00092 return true;
00093 }
00094
00095 void a2dStDrawToolFast::CleanupToolObjects()
00096 {
00097 GetCanvasView()->RemoveOverlayObject( m_canvasobject );
00098 GetCanvasView()->SetOverlayDrawStyle( RenderWIREFRAME_HighLight );
00099 m_original->SetVisible( true );
00100 }
00101
00102 void a2dStDrawToolFast::Render()
00103 {
00104 if ( m_canvasobject && GetBusy())
00105 {
00106 }
00107 }
00108
00109
00110
00111
00112
00113 A2D_BEGIN_EVENT_TABLE(a2dZoomFast,a2dStTool)
00114 A2D_EVT_CHAR(a2dZoomFast::OnChar)
00115 A2D_EVT_MOUSE_EVENTS(a2dZoomFast::OnMouseEvent)
00116 A2D_END_EVENT_TABLE()
00117
00118 a2dZoomFast::a2dZoomFast(a2dStToolContr* controller):a2dStTool(controller)
00119 {
00120 m_eventHandler = new a2dStToolFixedToolStyleEvtHandler( controller );
00121
00122 m_draggingCanvas = false;
00123 m_anotate = false;
00124 m_toolcursor = a2dCanvasGlobals->GetCursor( a2dCURSOR_MAGNIFIER );
00125 m_toolBusyCursor = a2dCanvasGlobals->GetCursor( a2dCURSOR_CROSS );
00126
00127 if ( GetCanvasView()->GetDrawer2D()->HasAlpha() || GetCanvasView()->GetTrippleBuf() )
00128 {
00129 SetFill( a2dFill( wxColour( 66, 159, 235, 50 ) ) );
00130 SetStroke( a2dStroke( wxColour( 66, 159, 235, 165 ), 2, a2dSTROKE_LONG_DASH) );
00131 }
00132 else
00133 {
00134 SetFill( *a2dTRANSPARENT_FILL );
00135 SetStroke( a2dStroke(*wxBLACK, 1, a2dSTROKE_LONG_DASH) );
00136 }
00137 }
00138
00139 a2dZoomFast::a2dZoomFast( const a2dZoomFast& other, CloneOptions options )
00140 :a2dStTool( other, options )
00141 {
00142 m_eventHandler = other.m_eventHandler;
00143
00144 m_anotate = other.m_anotate;
00145 m_draggingCanvas = false;
00146 m_toolcursor = other.m_toolcursor;
00147 m_toolBusyCursor = other.m_toolBusyCursor;
00148
00149 m_fill = other.m_fill;
00150 m_stroke = other.m_stroke;
00151 }
00152
00153 a2dObject* a2dZoomFast::Clone( CloneOptions options ) const
00154 {
00155 return new a2dZoomFast( *this, options );
00156 }
00157
00158 a2dZoomFast::~a2dZoomFast()
00159 {
00160 }
00161
00162 void a2dZoomFast::Render()
00163 {
00164 }
00165
00166 void a2dZoomFast::GenerateAnotation()
00167 {
00168
00169 a2dStTool::AddAnotationToPendingUpdateArea();
00170
00171 a2dRect* rec = wxStaticCast( m_canvasobject.Get(), a2dRect );
00172 m_anotation.Printf( _T("w %6.3f h %6.3f"), rec->GetWidth(), rec->GetHeight() );
00173 m_xanotation = m_x;
00174 m_yanotation = m_y;
00175
00176 wxCoord w, h, descent, external;
00177 GetTextExtent( m_anotation, &w, &h, &descent, &external );
00178
00179 m_xanotation = m_x + h;
00180 m_yanotation = m_y + h;
00181
00182 a2dStTool::AddAnotationToPendingUpdateArea();
00183 }
00184
00185 void a2dZoomFast::OnChar(wxKeyEvent& event)
00186 {
00187 if (!GetBusy())
00188 {
00189 switch(event.GetKeyCode())
00190 {
00191 case WXK_RETURN:
00192 {
00193 m_stcontroller->Zoomout();
00194 }
00195 break;
00196 case WXK_SUBTRACT:
00197 {
00198 m_stcontroller->ZoomUndo();
00199 }
00200 break;
00201 default:
00202 event.Skip();
00203 }
00204 }
00205 else
00206 event.Skip();
00207 }
00208
00209 void a2dZoomFast::OnMouseEvent(wxMouseEvent& event)
00210 {
00211 if (!m_active)
00212 {
00213 event.Skip();
00214 return;
00215 }
00216
00217 if( m_draggingCanvas )
00218 GetCanvasView()->SetCursor( a2dCanvasGlobals->GetCursor( a2dCURSOR_Move ) );
00219 else if ( GetBusy() )
00220 GetCanvasView()->SetCursor( m_toolBusyCursor );
00221 else
00222 GetCanvasView()->SetCursor( m_toolcursor );
00223
00224 m_x = event.GetX();
00225 m_y = event.GetY();
00226
00227 if (event.LeftDClick() && !GetBusy())
00228 {
00229 m_stcontroller->Zoomout();
00230 }
00231 else if (event.LeftDown() && !GetBusy())
00232 {
00233 SetIgnorePendingObjects( true );
00234 MouseToToolWorld( m_x, m_y, m_xwprev, m_ywprev );
00235 m_parentobject = GetCanvasView()->GetShowObject();
00236 a2dRect* rec = new a2dRect( m_xwprev, m_ywprev, 0, 0, 0);
00237 m_canvasobject = rec;
00238 if ( GetCanvasView()->GetTrippleBuf() )
00239 GetCanvasView()->AddOverlayObject( rec );
00240 else
00241 AddDecorationObject( rec );
00242 rec->SetCanvasDocument( GetCanvasView()->GetCanvasDocument() );
00243 rec->SetFill( m_fill );
00244 rec->SetStroke( m_stroke );
00245 rec->Update( a2dCanvasObject::updatemask_force );
00246 m_pending = true;
00247
00248
00249
00250
00251 event.Skip();
00252 EnterBusyMode();
00253 }
00254 else if ( event.LeftUp() && GetBusy())
00255 {
00256 SetIgnorePendingObjects( false );
00257 a2dRect* rec = wxStaticCast( m_canvasobject.Get(), a2dRect );
00258
00259 double w = GetDrawer2D()->WorldToDeviceXRel( rec->GetWidth() );
00260 double h = GetDrawer2D()->WorldToDeviceYRel( rec->GetHeight() );
00261
00262
00263
00264 if (fabs( w ) < 3 && fabs( h )< 3)
00265 {
00266 GetDisplayWindow()->Refresh();
00267 FinishBusyMode();
00268 event.Skip();
00269 }
00270 else
00271 {
00272 rec->Update( a2dCanvasObject::updatemask_force );
00273 double x1 = rec->GetBbox().GetMinX();
00274
00275 double y1 = rec->GetBbox().GetMinY();
00276
00277
00278 a2dBoundingBox* bbox = new a2dBoundingBox(GetDrawer2D()->GetVisibleMinX(),
00279 GetDrawer2D()->GetVisibleMinY(),
00280 GetDrawer2D()->GetVisibleMaxX(),
00281 GetDrawer2D()->GetVisibleMaxY()
00282 );
00283
00284 m_stcontroller->GetZoomList().Insert(bbox);
00285
00286 GetDrawer2D()->SetMappingWidthHeight(x1,y1, fabs(rec->GetWidth()),fabs(rec->GetHeight()));
00287
00288 a2dDocviewGlobals->RecordF( this, _T("zoom %f %f %f %f"), x1, y1, x1+rec->GetWidth(), y1+rec->GetHeight() );
00289
00290
00291
00292
00293
00294 FinishBusyMode();
00295 if ( GetCanvasView()->GetTrippleBuf() )
00296 GetCanvasView()->RemoveOverlayObject( rec );
00297 event.Skip();
00298 }
00299 }
00300 else if ((event.Dragging() && GetBusy()) && !m_draggingCanvas )
00301 {
00302 a2dRect* rec = wxStaticCast( m_canvasobject.Get(), a2dRect );
00303
00304 MouseToToolWorld( m_x, m_y, m_xwprev, m_ywprev );
00305
00306 rec->SetWidth( m_xwprev - rec->GetPosX() );
00307 rec->SetHeight( m_ywprev - rec->GetPosY() );
00308 rec->SetPending( true );
00309 m_pending = true;
00310 }
00311 else if ( event.Dragging() && m_draggingCanvas )
00312 {
00313 double dxworld = GetDrawer2D()->DeviceToWorldXRel( floor( m_xprev-m_x + 0.5 ) );
00314 double dyworld = GetDrawer2D()->DeviceToWorldYRel( floor( m_yprev-m_y + 0.5 ) );
00315
00316 GetCanvasView()->GetCanvas()->ScrollWindowConstrained( dxworld, dyworld );
00317 m_xprev = m_x;
00318 m_yprev = m_y;
00319 }
00320 else if( event.RightDown() && !m_draggingCanvas )
00321 {
00322 GetCanvasView()->SetCursor( a2dCanvasGlobals->GetCursor( a2dCURSOR_Move ) );
00323 m_draggingCanvas = true;
00324 m_xprev = m_x;
00325 m_yprev = m_y;
00326 m_dragstartx = m_x;
00327 m_dragstarty = m_y;
00328 }
00329 else if( event.RightUp() && m_draggingCanvas )
00330 {
00331 m_draggingCanvas = false;
00332 if ( m_dragstartx == m_xprev && m_dragstarty == m_yprev )
00333 GetCanvasView()->GetDisplayWindow()->PopupMenu( m_stcontroller->GetMousePopupMenu(), m_x, m_y );
00334 if (m_oneshot)
00335 StopTool();
00336 }
00337 else
00338 event.Skip();
00339 }
00340
00341 A2D_BEGIN_EVENT_TABLE(a2dFastSelect,a2dStTool)
00342 A2D_EVT_CHAR(a2dFastSelect::OnChar)
00343 A2D_EVT_MOUSE_EVENTS(a2dFastSelect::OnMouseEvent)
00344 A2D_END_EVENT_TABLE()
00345
00346 a2dFastSelect::a2dFastSelect(a2dStToolContr* controller):a2dStTool(controller)
00347 {
00348 m_eventHandler = new a2dStToolFixedToolStyleEvtHandler( controller );
00349
00350 m_shift_is_add = false;
00351
00352 m_anotate = false;
00353 m_toolcursor = a2dCanvasGlobals->GetCursor( a2dCURSOR_CROSS );
00354 m_toolBusyCursor = a2dCanvasGlobals->GetCursor( a2dCURSOR_CROSS );
00355
00356 if ( GetCanvasView()->GetDrawer2D()->HasAlpha() || GetCanvasView()->GetTrippleBufHasAlpha() )
00357 {
00358 SetFill( a2dFill( wxColour( 233, 15, 23, 20 ) ) );
00359 SetStroke( a2dStroke( wxColour( 255, 59, 25, 65 ), 1, a2dSTROKE_LONG_DASH) );
00360 }
00361 else
00362 {
00363 SetFill( *a2dTRANSPARENT_FILL );
00364 SetStroke( a2dStroke(*wxRED, 1, a2dSTROKE_LONG_DASH) );
00365 }
00366 }
00367
00368 a2dFastSelect::~a2dFastSelect()
00369 {
00370 }
00371
00372 void a2dFastSelect::Render()
00373 {
00374 }
00375
00376 void a2dFastSelect::DeselectAll()
00377 {
00378 GetCanvasCommandProcessor()->Submit( new a2dCommand_Select( a2dCommand_Select::Args().what(a2dCommand_Select::DeSelectAll) ) );
00379 }
00380
00381 void a2dFastSelect::GenerateAnotation()
00382 {
00383
00384 a2dStTool::AddAnotationToPendingUpdateArea();
00385
00386 a2dRect* rec = wxStaticCast( m_canvasobject.Get(), a2dRect );
00387 m_anotation.Printf( _T("w %6.3f h %6.3f"), rec->GetWidth(), rec->GetHeight() );
00388 m_xanotation = m_x;
00389 m_yanotation = m_y;
00390
00391 wxCoord w, h, descent, external;
00392 GetTextExtent( m_anotation, &w, &h, &descent, &external );
00393
00394 m_xanotation = m_x + h;
00395 m_yanotation = m_y + h;
00396
00397 a2dStTool::AddAnotationToPendingUpdateArea();
00398 }
00399
00400 void a2dFastSelect::OnChar(wxKeyEvent& event)
00401 {
00402 if (!GetBusy())
00403 {
00404 switch(event.GetKeyCode())
00405 {
00406 case WXK_RETURN:
00407 {
00408 m_stcontroller->Zoomout();
00409 }
00410 break;
00411 case WXK_SUBTRACT:
00412 {
00413 m_stcontroller->ZoomUndo();
00414 }
00415 break;
00416 default:
00417 event.Skip();
00418 }
00419 }
00420 else
00421 event.Skip();
00422 }
00423
00424 void a2dFastSelect::OnMouseEvent(wxMouseEvent& event)
00425 {
00426 if (!m_active)
00427 {
00428 event.Skip();
00429 return;
00430 }
00431
00432 m_x = event.GetX();
00433 m_y = event.GetY();
00434
00435 MouseToToolWorld( m_x, m_y, m_xwprev, m_ywprev );
00436
00437 a2dRestrictionEngine *restrict = a2dCanvasGlobals->GetRestrictionEngine();
00438 if(restrict)
00439 {
00440 restrict->SetShiftKeyDown( event.ShiftDown() );
00441 restrict->SetAltKeyDown( event.AltDown() );
00442 restrict->RestrictPoint(m_xwprev, m_ywprev);
00443 }
00444
00445 if ( event.Moving() )
00446 {
00447 if ( !GetBusy() )
00448 {
00449 double xWorld, yWorld;
00450 GetCanvasView()->MouseToToolWorld( m_x, m_y, xWorld, yWorld );
00451
00452 static a2dCanvasObject* oldhitobject = NULL;
00453 a2dCanvasObject* hitobject = NULL;
00454 hitobject = GetCanvasView()->IsHitWorld( xWorld, yWorld, wxLAYER_ALL, a2dCANOBJHITOPTION_LAYERS, true );
00455 if ( hitobject )
00456 {
00457 GetCanvasView()->SetCursor( a2dCanvasGlobals->GetCursor( a2dCURSOR_HAND ) );
00458
00459 if ( oldhitobject )
00460 {
00461 if ( hitobject != oldhitobject )
00462 {
00463 GetCanvasDocument()->SetIgnorePendingObjects( true );
00464 GetCanvasView()->RemoveOverlayObject( oldhitobject );
00465 GetCanvasView()->SetOverlayDrawStyle( RenderWIREFRAME_HighLight );
00466 GetCanvasView()->AddOverlayObject( hitobject );
00467 hitobject->SetPending( true );
00468 GetCanvasDocument()->SetIgnorePendingObjects( false );
00469 oldhitobject = hitobject;
00470 }
00471 }
00472 else
00473 {
00474 GetCanvasDocument()->SetIgnorePendingObjects( true );
00475 GetCanvasView()->SetOverlayDrawStyle( RenderWIREFRAME_HighLight );
00476 GetCanvasView()->AddOverlayObject( hitobject );
00477 hitobject->SetPending( true );
00478 GetCanvasDocument()->SetIgnorePendingObjects( false );
00479 oldhitobject = hitobject;
00480 }
00481 }
00482 else if ( oldhitobject )
00483 {
00484 GetCanvasView()->SetCursor( m_toolcursor );
00485 GetCanvasDocument()->SetIgnorePendingObjects( true );
00486 GetCanvasView()->RemoveOverlayObject( oldhitobject );
00487 GetCanvasDocument()->SetIgnorePendingObjects( false );
00488 oldhitobject = NULL;
00489 }
00490 else
00491 GetCanvasView()->SetCursor( m_toolcursor );
00492 }
00493 else
00494 GetCanvasView()->SetCursor( m_toolBusyCursor );
00495 }
00496 else
00497 {
00498 GetCanvasView()->SetOverlayDrawStyle( RenderLAYERED );
00499 if ( GetBusy() )
00500 GetCanvasView()->SetCursor( m_toolBusyCursor );
00501 else
00502 GetCanvasView()->SetCursor( m_toolcursor );
00503 }
00504
00505 if (event.LeftDClick() && !GetBusy())
00506 {
00507 m_stcontroller->Zoomout();
00508 }
00509 else if (event.LeftDown() && !GetBusy())
00510 {
00511 SetIgnorePendingObjects( true );
00512 m_parentobject = GetCanvasView()->GetShowObject();
00513 a2dRect* rec = new a2dRect( m_xwprev, m_ywprev, 0, 0, 0);
00514 m_canvasobject = rec;
00515 rec->SetFill( m_fill );
00516 rec->SetStroke( m_stroke );
00517 rec->Update( a2dCanvasObject::updatemask_force );
00518 if ( GetCanvasView()->GetTrippleBuf() )
00519 rec->SetCanvasDocument( GetCanvasView()->GetCanvasDocument() );
00520 else
00521 GetCanvasView()->AddOverlayObject( rec );
00522 GetCanvasView()->SetOverlayDrawStyle( RenderLAYERED );
00523 m_pending = true;
00524
00525
00526
00527
00528 event.Skip();
00529 EnterBusyMode();
00530 }
00531 else if ( event.LeftUp() && GetBusy())
00532 {
00533 SetIgnorePendingObjects( false );
00534
00535 a2dRect* rec = wxStaticCast( m_canvasobject.Get(), a2dRect );
00536 rec->Update( a2dCanvasObject::updatemask_force );
00537 GetCanvasView()->AddPendingUpdateArea(rec->GetBbox());
00538 GetCanvasView()->RemoveOverlayObject( rec );
00539 GetCanvasView()->SetOverlayDrawStyle( RenderWIREFRAME_HighLight );
00540
00541 double w = GetDrawer2D()->WorldToDeviceXRel( rec->GetWidth() );
00542 double h = GetDrawer2D()->WorldToDeviceYRel( rec->GetHeight() );
00543
00544 if (fabs( w ) < 3 && fabs( h )< 3)
00545 {
00546
00547
00548 a2dCanvasObject* hitobject = GetCanvasView()->IsHitWorld( m_xwprev, m_ywprev, wxLAYER_ALL, a2dCANOBJHITOPTION_LAYERS, true );
00549
00550 if( m_shift_is_add )
00551 {
00552 if ( !event.m_shiftDown )
00553 {
00554
00555 DeselectAll();
00556
00557 if ( hitobject )
00558 {
00559 GetCanvasCommandProcessor()->Submit(
00560 new a2dCommand_SetFlag( hitobject, a2dCanvasOFlags::SELECTED, !hitobject->GetSelected() )
00561 );
00562 }
00563 }
00564 else
00565 {
00566
00567 if ( hitobject )
00568 {
00569 GetCanvasCommandProcessor()->Submit(
00570 new a2dCommand_SetFlag( hitobject, a2dCanvasOFlags::SELECTED, true )
00571 );
00572 }
00573 }
00574
00575 if (!hitobject)
00576 {
00577 if( !m_oneshot )
00578 event.Skip();
00579 FinishBusyMode();
00580 return;
00581 }
00582 }
00583 else
00584 {
00585 if (!hitobject)
00586 {
00587 if( !m_oneshot )
00588 event.Skip();
00589 FinishBusyMode();
00590 return;
00591 }
00592
00593 if ( event.m_shiftDown || hitobject->GetSelected())
00594 {
00595 GetCanvasCommandProcessor()->Submit(
00596 new a2dCommand_SetFlag( hitobject, a2dCanvasOFlags::SELECTED, false )
00597 );
00598 }
00599 else
00600 {
00601 GetCanvasCommandProcessor()->Submit(
00602 new a2dCommand_SetFlag( hitobject, a2dCanvasOFlags::SELECTED, true )
00603 );
00604 }
00605 }
00606 }
00607 else
00608 {
00609 if( m_shift_is_add )
00610 {
00611
00612
00613
00614 if (!event.m_shiftDown)
00615 {
00616 DeselectAll();
00617 GetCanvasCommandProcessor()->Submit(
00618 new a2dCommand_Select( a2dCommand_Select::Args()
00619 .what(a2dCommand_Select::SelectRect)
00620 .x1( rec->GetBbox().GetMinX() )
00621 .y1( rec->GetBbox().GetMinY() )
00622 .x2( rec->GetBbox().GetMaxX() )
00623 .y2( rec->GetBbox().GetMaxY() )
00624 )
00625 );
00626 }
00627 else
00628 {
00629 GetCanvasCommandProcessor()->Submit(
00630 new a2dCommand_Select( a2dCommand_Select::Args()
00631 .what(a2dCommand_Select::SelectRect)
00632 .x1( rec->GetBbox().GetMinX() )
00633 .y1( rec->GetBbox().GetMinY() )
00634 .x2( rec->GetBbox().GetMaxX() )
00635 .y2( rec->GetBbox().GetMaxY() )
00636 )
00637 );
00638 }
00639 }
00640 else
00641 {
00642 if (event.m_shiftDown)
00643 {
00644 GetCanvasCommandProcessor()->Submit(
00645 new a2dCommand_Select( a2dCommand_Select::Args()
00646 .what(a2dCommand_Select::DeSelectRect)
00647 .x1( rec->GetBbox().GetMinX() )
00648 .y1( rec->GetBbox().GetMinY() )
00649 .x2( rec->GetBbox().GetMaxX() )
00650 .y2( rec->GetBbox().GetMaxY() )
00651 )
00652 );
00653 }
00654 else
00655 {
00656 GetCanvasCommandProcessor()->Submit(
00657 new a2dCommand_Select( a2dCommand_Select::Args()
00658 .what(a2dCommand_Select::SelectRect)
00659 .x1( rec->GetBbox().GetMinX() )
00660 .y1( rec->GetBbox().GetMinY() )
00661 .x2( rec->GetBbox().GetMaxX() )
00662 .y2( rec->GetBbox().GetMaxY() )
00663 )
00664 );
00665 }
00666 }
00667 }
00668
00669 m_pending = true;
00670 FinishBusyMode();
00671
00672 GetCanvasView()->RemoveOverlayObject( rec );
00673 GetCanvasView()->Update( a2dCANVIEW_UPDATE_SYNC_DRAWERS );
00674 }
00675 else if ((event.Dragging() && GetBusy()) )
00676 {
00677 a2dRect* rec = wxStaticCast( m_canvasobject.Get(), a2dRect );
00678 if ( GetCanvasView()->GetTrippleBuf() )
00679 {
00680 GetCanvasDocument()->SetIgnorePendingObjects( true );
00681
00682 int x,y,width,height;
00683 a2dIterC ic( GetCanvasView() );
00684 a2dIterCU cu( ic, a2dIDENTITY_MATRIX );
00685 wxRect absarea = rec->GetAbsoluteArea( ic );
00686 x = absarea.GetX();
00687 y = absarea.GetY();
00688 width = absarea.GetWidth();
00689 height = absarea.GetHeight();
00690
00691 rec->SetWidth( m_xwprev - rec->GetPosX() );
00692 rec->SetHeight( m_ywprev - rec->GetPosY() );
00693 rec->Update( a2dCanvasObject::updatemask_force );
00694 rec->SetPending( false );
00695
00696 wxRect absarea2 = rec->GetAbsoluteArea( ic );
00697 absarea2.Union( absarea );
00698 x = absarea2.GetX();
00699 y = absarea2.GetY();
00700 width = absarea2.GetWidth();
00701 height = absarea2.GetHeight();
00702
00703 GetCanvasView()->ClearArea( x, y, width, height );
00704 GetCanvasView()->SetOverlayDrawStyle( RenderTOOL_OBJECTS_STYLED );
00705 GetCanvasView()->RenderChildObject( rec );
00706 GetCanvasView()->BlitBuffer( x, y, width, height,0,0 );
00707
00708 GetCanvasDocument()->SetIgnorePendingObjects( false );
00709 GetCanvasView()->SetOverlayDrawStyle( RenderTOOL_OBJECTS_STYLED );
00710 }
00711 else
00712 {
00713 rec->SetWidth( m_xwprev - rec->GetPosX() );
00714 rec->SetHeight( m_ywprev - rec->GetPosY() );
00715 rec->SetPending( true );
00716 }
00717 }
00718 else
00719 event.Skip();
00720 }
00721
00722 A2D_BEGIN_EVENT_TABLE(a2dFastSelect2,a2dStTool)
00723 A2D_EVT_CHAR(a2dFastSelect2::OnChar)
00724 A2D_EVT_MOUSE_EVENTS(a2dFastSelect2::OnMouseEvent)
00725 A2D_END_EVENT_TABLE()
00726
00727 a2dFastSelect2::a2dFastSelect2(a2dStToolContr* controller):a2dStTool(controller)
00728 {
00729 m_eventHandler = new a2dStToolFixedToolStyleEvtHandler( controller );
00730
00731 m_selectMode = true;
00732
00733 m_anotate = false;
00734 m_toolcursor = a2dCanvasGlobals->GetCursor( a2dCURSOR_CROSS );
00735 m_toolBusyCursor = a2dCanvasGlobals->GetCursor( a2dCURSOR_CROSS );
00736
00737
00738 SetFill( *a2dTRANSPARENT_FILL );
00739 SetStroke( a2dStroke(*wxBLACK, 2, a2dSTROKE_LONG_DASH) );
00740 }
00741
00742 a2dFastSelect2::~a2dFastSelect2()
00743 {
00744 }
00745
00746 void a2dFastSelect2::SelectAll( bool select )
00747 {
00748 a2dCanvasObjectList objects;
00749 m_parentobject->GetChildObjectList()->CollectObjects( &objects, wxT(""), a2dCanvasOFlags::SELECTED );
00750 GetCanvasCommandProcessor()->SubmitMultiple(
00751 new a2dCommand_SetFlag( 0, a2dCanvasOFlags::SELECTED, select ),
00752 &objects
00753 );
00754 }
00755
00756 void a2dFastSelect2::GenerateAnotation()
00757 {
00758
00759 a2dStTool::AddAnotationToPendingUpdateArea();
00760
00761 a2dRect* rec = wxStaticCast( m_canvasobject.Get(), a2dRect );
00762 m_anotation.Printf( _T("w %6.3f h %6.3f"), rec->GetWidth(), rec->GetHeight() );
00763 m_xanotation = m_x;
00764 m_yanotation = m_y;
00765
00766 wxCoord w, h, descent, external;
00767 GetTextExtent( m_anotation, &w, &h, &descent, &external );
00768
00769 m_xanotation = m_x + h;
00770 m_yanotation = m_y + h;
00771
00772 a2dStTool::AddAnotationToPendingUpdateArea();
00773 }
00774
00775 void a2dFastSelect2::OnChar(wxKeyEvent& event)
00776 {
00777 if (!GetBusy())
00778 {
00779 switch(event.GetKeyCode())
00780 {
00781 case WXK_RETURN:
00782 {
00783 m_stcontroller->Zoomout();
00784 }
00785 break;
00786 case WXK_SUBTRACT:
00787 {
00788 m_stcontroller->ZoomUndo();
00789 }
00790 break;
00791 default:
00792 event.Skip();
00793 }
00794 }
00795 else
00796 event.Skip();
00797 }
00798
00799 void a2dFastSelect2::OnMouseEvent(wxMouseEvent& event)
00800 {
00801 if (!m_active)
00802 {
00803 event.Skip();
00804 return;
00805 }
00806
00807 if ( GetBusy() )
00808 GetCanvasView()->SetCursor( m_toolBusyCursor );
00809 else
00810 GetCanvasView()->SetCursor( m_toolcursor );
00811
00812 m_x = event.GetX();
00813 m_y = event.GetY();
00814
00815 MouseToToolWorld( m_x, m_y, m_xwprev, m_ywprev );
00816
00817 a2dRestrictionEngine *restrict = a2dCanvasGlobals->GetRestrictionEngine();
00818 if(restrict)
00819 {
00820 restrict->SetShiftKeyDown( event.ShiftDown() );
00821 restrict->SetAltKeyDown( event.AltDown() );
00822 restrict->RestrictPoint(m_xwprev, m_ywprev);
00823 }
00824
00825 if ( event.Moving() )
00826 {
00827 if ( !GetBusy() )
00828 {
00829 double xWorld, yWorld;
00830 GetCanvasView()->MouseToToolWorld( m_x, m_y, xWorld, yWorld );
00831 if ( GetCanvasView()->IsHitWorld( xWorld, yWorld, wxLAYER_ALL, a2dCANOBJHITOPTION_LAYERS, true ) )
00832 GetCanvasView()->SetCursor( a2dCanvasGlobals->GetCursor( a2dCURSOR_HAND ) );
00833 else
00834 GetCanvasView()->SetCursor( m_toolcursor );
00835
00836 }
00837 else
00838 GetCanvasView()->SetCursor( m_toolBusyCursor );
00839 }
00840
00841 if (event.LeftDClick() && !GetBusy())
00842 {
00843 m_stcontroller->Zoomout();
00844 }
00845 else if (event.LeftDown() && !GetBusy())
00846 {
00847 SetIgnorePendingObjects( true );
00848 m_parentobject = GetCanvasView()->GetShowObject();
00849 a2dRect* rec = new a2dRect( m_xwprev, m_ywprev, 0, 0, 0);
00850 m_canvasobject = rec;
00851 rec->SetCanvasDocument( GetCanvasView()->GetCanvasDocument() );
00852 rec->SetFill( m_fill );
00853 rec->SetStroke( m_stroke );
00854 rec->Update( a2dCanvasObject::updatemask_force );
00855 m_pending = true;
00856
00857
00858
00859
00860 event.Skip();
00861 EnterBusyMode();
00862 }
00863 else if ( event.LeftUp() && GetBusy())
00864 {
00865 SetIgnorePendingObjects( false );
00866
00867 a2dRect* rec = wxStaticCast( m_canvasobject.Get(), a2dRect );
00868 rec->Update( a2dCanvasObject::updatemask_force );
00869 GetCanvasView()->AddPendingUpdateArea(rec->GetBbox());
00870
00871 double w = GetDrawer2D()->WorldToDeviceXRel( rec->GetWidth() );
00872 double h = GetDrawer2D()->WorldToDeviceYRel( rec->GetHeight() );
00873
00874 if (fabs( w ) < 3 && fabs( h )< 3)
00875 {
00876
00877
00878 a2dCanvasObject* hitobject = GetCanvasView()->IsHitWorld( m_xwprev, m_ywprev, wxLAYER_ALL, a2dCANOBJHITOPTION_LAYERS, true );
00879
00880 if ( event.m_shiftDown && event.m_controlDown )
00881 {
00882 if (!hitobject)
00883 {
00884 if( !m_oneshot )
00885 event.Skip();
00886 FinishBusyMode();
00887 return;
00888 }
00889
00890
00891 SelectAll(m_selectMode);
00892
00893 GetCanvasCommandProcessor()->Submit(
00894 new a2dCommand_SetFlag( hitobject, a2dCanvasOFlags::SELECTED, !hitobject->GetSelected() )
00895 );
00896 }
00897 }
00898 else
00899 {
00900 a2dWalker_CollectCanvasObjects collector( a2dCanvasOFlags::VISIBLE );
00901 collector.SetRecursionDepth( 2 );
00902
00903
00904 collector.SetBoundingBox( rec->GetBbox() );
00905 collector.Start( GetCanvasView()->GetShowObject() );
00906
00907 if ( event.m_shiftDown && event.m_controlDown )
00908 {
00909 GetCanvasCommandProcessor()->SubmitMultiple(
00910 new a2dCommand_SetFlag( 0, a2dCanvasOFlags::SELECTED, !m_selectMode ),
00911 &collector.m_found
00912 );
00913 }
00914 else
00915 {
00916 GetCanvasCommandProcessor()->SubmitMultiple(
00917 new a2dCommand_SetFlag( 0, a2dCanvasOFlags::SELECTED, m_selectMode ),
00918 &collector.m_found
00919 );
00920 }
00921 }
00922
00923 m_pending = true;
00924 FinishBusyMode();
00925 GetCanvasView()->Update( a2dCANVIEW_UPDATE_SYNC_DRAWERS );
00926 }
00927 else if ((event.Dragging() && GetBusy()) )
00928 {
00929 a2dRect* rec = wxStaticCast( m_canvasobject.Get(), a2dRect );
00930
00931 GetDrawer2D()->BeginDraw();
00932 GetDrawer2D()->ResetStyle();
00933 GetDrawer2D()->SetDrawStyle( a2dWIREFRAME_INVERT );
00934 GetDrawer2D()->SetDrawerFill( m_fill );
00935 GetDrawer2D()->SetDrawerStroke( *a2dBLACK_STROKE );
00936 GetDrawer2D()->DrawRoundedRectangle( rec->GetPosX(), rec->GetPosY(),
00937 rec->GetWidth(),rec->GetHeight(), 0 );
00938
00939 rec->SetWidth( m_xwprev - rec->GetPosX() );
00940 rec->SetHeight( m_ywprev - rec->GetPosY() );
00941
00942 GetDrawer2D()->DrawRoundedRectangle( rec->GetPosX(), rec->GetPosY(),
00943 rec->GetWidth(),rec->GetHeight(), 0 );
00944
00945 GetDrawer2D()->BlitBuffer();
00946
00947 GetDrawer2D()->EndDraw();
00948 GetDrawer2D()->SetDrawStyle( a2dFILLED );
00949
00950 }
00951 else
00952 event.Skip();
00953 }
00954
00955
00956 A2D_BEGIN_EVENT_TABLE(a2dFastDragMultiTool,a2dStTool)
00957 A2D_EVT_IDLE( a2dFastDragMultiTool::OnIdle )
00958 A2D_EVT_CHAR( a2dFastDragMultiTool::OnChar )
00959 A2D_EVT_MOUSE_EVENTS( a2dFastDragMultiTool::OnMouseEvent )
00960 A2D_END_EVENT_TABLE()
00961
00962 a2dFastDragMultiTool::a2dFastDragMultiTool(a2dStToolContr* controller):a2dStTool(controller)
00963 {
00964 m_eventHandler = new a2dStToolFixedToolStyleEvtHandler( controller );
00965
00966 m_anotate = false;
00967 m_mode = 0;
00968 SetFill( *a2dTRANSPARENT_FILL );
00969 SetStroke( a2dStroke(*wxRED, 0, a2dSTROKE_SOLID) );
00970 m_toolBusyCursor = a2dCanvasGlobals->GetCursor( a2dCURSOR_CROSS );
00971 }
00972
00973 a2dFastDragMultiTool::~a2dFastDragMultiTool()
00974 {
00975 }
00976
00977 void a2dFastDragMultiTool::OnChar(wxKeyEvent& event)
00978 {
00979 switch(event.GetKeyCode())
00980 {
00981 case WXK_TAB:
00982 {
00983 m_mode++;
00984 SetMode( m_mode );
00985 }
00986 break;
00987 case WXK_SPACE:
00988 {
00989 if (GetBusy())
00990 {}
00991 }
00992 break;
00993
00994 default:
00995 event.Skip();
00996 }
00997 }
00998
00999 void a2dFastDragMultiTool::OnMouseEvent(wxMouseEvent& event)
01000 {
01001 if (!m_active)
01002 {
01003 event.Skip();
01004 return;
01005 }
01006
01007 m_x = event.GetX();
01008 m_y = event.GetY();
01009 MouseToToolWorld( m_x, m_y, m_xwprev, m_ywprev );
01010
01011 a2dRestrictionEngine *restrict = a2dCanvasGlobals->GetRestrictionEngine();
01012 if(restrict)
01013 {
01014 restrict->SetShiftKeyDown( event.ShiftDown() );
01015 restrict->SetAltKeyDown( event.AltDown() );
01016 restrict->RestrictPoint(m_xwprev, m_ywprev);
01017 }
01018
01019 if (event.LeftDown())
01020 {
01021 if ( m_mode == 0 )
01022 {
01023 m_original = GetCanvasView()->IsHitWorld( m_xwprev, m_ywprev, wxLAYER_ALL, a2dCANOBJHITOPTION_LAYERS, true );
01024
01025 if (!m_original || !m_original->IsSelected() || !m_original->GetDraggable() )
01026 {
01027 m_original=0;
01028 return;
01029 }
01030
01031 GetCanvasView()->GetShowObject()->CollectObjects( &m_objects,_T(""),a2dCanvasOFlags::SELECTED );
01032 }
01033 else
01034 {
01035
01036 GetCanvasView()->GetShowObject()->CollectObjects( &m_objects,_T(""),a2dCanvasOFlags::SELECTED );
01037 m_original = m_objects.front();
01038 }
01039
01040 EnterBusyMode();
01041 GetCanvasView()->Freeze();
01042 SetIgnorePendingObjects( true );
01043
01044 m_startMousexw = m_xwprev;
01045 m_startMouseyw = m_ywprev;
01046 m_startObjectx = m_original->GetPosX();
01047 m_startObjecty = m_original->GetPosY();
01048 m_prevxanotation = m_x;
01049 m_prevyanotation = m_y;
01050
01051 m_pending = true;
01052 }
01053 else if (event.LeftUp() && GetBusy() )
01054 {
01055 GetCanvasView()->Thaw(false);
01056 SetIgnorePendingObjects( false );
01057 FinishBusyMode();
01058
01059
01060
01061
01062 }
01063 else if ( GetBusy() )
01064 {
01065 double dxm = m_xwprev-m_startMousexw;
01066 double dym = m_ywprev-m_startMouseyw;
01067 AdjustShift( &dxm, &dym );
01068
01069
01070 double dx = m_canvasobject->GetPosX();
01071 double dy = m_canvasobject->GetPosY();
01072 m_canvasobject->SetPosXY( dxm+m_startObjectx, dym+m_startObjecty );
01073 dx = m_canvasobject->GetPosX() - dx;
01074 dy = m_canvasobject->GetPosY() - dy;
01075
01076 DragRelative( dx, dy );
01077 }
01078 else
01079 {
01080 event.Skip();
01081 }
01082 }
01083
01084 bool a2dFastDragMultiTool::EnterBusyMode()
01085 {
01086 if(!a2dStTool::EnterBusyMode())
01087 return false;
01088 CaptureMouse();
01089 return true;
01090 }
01091
01092 void a2dFastDragMultiTool::FinishBusyMode()
01093 {
01094 ReleaseMouse();
01095
01096 double dx = m_canvasobject->GetPosX() - m_startObjectx;
01097 double dy = m_canvasobject->GetPosY() - m_startObjecty;
01098
01099 GetCanvasCommandProcessor()->Submit( new a2dCommand_MoveMask( dx, dy) );
01100
01101 m_objects.clear();
01102
01103 a2dStTool::FinishBusyMode();
01104 }
01105
01106 void a2dFastDragMultiTool::AbortBusyMode()
01107 {
01108 ReleaseMouse();
01109 a2dStTool::AbortBusyMode();
01110 }
01111
01112 void a2dFastDragMultiTool::CaptureMouse()
01113 {
01114 wxASSERT( m_canvasobject );
01115 GetCanvasView()->SetCaptured( m_canvasobject );
01116 GetCanvasView()->GetDisplayWindow()->CaptureMouse();
01117 }
01118
01119 void a2dFastDragMultiTool::ReleaseMouse()
01120 {
01121 GetCanvasView()->SetCaptured( NULL );
01122 GetCanvasView()->GetDisplayWindow()->ReleaseMouse();
01123 }
01124
01125 void a2dFastDragMultiTool::DragRelative( double x, double y )
01126 {
01127 if( !x && !y )
01128 return;
01129
01130 m_canvasobject->Translate( -x, -y);
01131
01132 GetDrawer2D()->BeginDraw();
01133 GetDrawer2D()->ResetStyle();
01134 GetDrawer2D()->SetDrawStyle( a2dWIREFRAME_INVERT );
01135 GetDrawer2D()->SetDrawerFill( m_fill );
01136 GetDrawer2D()->SetDrawerStroke( *a2dBLACK_STROKE );
01137
01138 a2dIterC ic( GetCanvasView() );
01139 ic.SetDisableInvert( true );
01140
01141
01142 a2dAffineMatrix cworld= GetCanvasView()->GetShowObject()->GetTransformMatrix();
01143 cworld.Invert();
01144
01145 OVERLAP clipparent = _IN;
01146 ic.SetObjectFilter( new a2dCanvasObjectFilterToolObjects( a2dCanvasObject::PROPID_ToolObject, a2dCanvasOFlags::VISIBLE ) );
01147 ic.SetLayer( wxLAYER_ALL );
01148
01149 a2dCanvasObjectList::iterator iter;
01150 for( iter = m_copies.begin(); iter != m_copies.end(); ++iter )
01151 {
01152 a2dCanvasObject *copy = *iter;
01153 a2dIterCU cu( ic, cworld );
01154 GetDrawer2D()->SetDisableDrawing( true );
01155 copy->SetHasToolObjectsBelow(true);
01156 copy->Render( ic, clipparent );
01157 ic.Reset();
01158 GetDrawer2D()->SetDisableDrawing( false );
01159 }
01160
01161
01162
01163 for( iter = m_copies.begin(); iter != m_copies.end(); ++iter )
01164 {
01165 a2dCanvasObject *obj = *iter;
01166 obj->Translate( x, y);
01167 }
01168
01169 for( iter = m_copies.begin(); iter != m_copies.end(); ++iter )
01170 {
01171 a2dCanvasObject *copy = *iter;
01172 a2dIterCU cu( ic, cworld );
01173 GetDrawer2D()->SetDisableDrawing( true );
01174 copy->SetHasToolObjectsBelow(true);
01175 copy->Render( ic, clipparent );
01176 ic.Reset();
01177 GetDrawer2D()->SetDisableDrawing( false );
01178 }
01179
01180 GenerateAnotation();
01181
01182 GetDrawer2D()->BlitBuffer();
01183
01184 GetDrawer2D()->EndDraw();
01185 GetDrawer2D()->SetDrawStyle( a2dFILLED );
01186
01187
01188 m_pending = true;
01189 }
01190
01191 void a2dFastDragMultiTool::Render()
01192 {
01193 return;
01194 if ( m_canvasobject && GetBusy())
01195 {
01196 a2dDrawer2D* draw = GetDrawer2D();
01197 GetDrawer2D()->BlitBuffer();
01198
01199 a2dCanvasDocument* doc = GetCanvasView()->GetCanvasDocument();
01200
01201 wxClientDC* dc = new wxClientDC( GetCanvasView()->GetDisplayWindow() );
01202
01203 a2dDcDrawer* dcdrawer = new a2dDcDrawer( *GetDrawer2D() );
01204 dcdrawer->SetRenderDC(dc);
01205 dcdrawer->BeginDraw();
01206 dcdrawer->ResetStyle();
01207 dcdrawer->SetDrawerFill( m_fill );
01208 dcdrawer->SetDrawerStroke( m_stroke );
01209 dcdrawer->SetDrawerStroke( *a2dBLACK_STROKE );
01210 dcdrawer->SetDrawStyle( a2dFIX_STYLE );
01211
01212 a2dSmrtPtr< a2dCanvasView > view = new a2dCanvasView( dcdrawer );
01213
01214 view->SetEvtHandlerEnabled( false );
01215 view->SetDocument( doc );
01216 view->SetShowObject( view->GetShowObject());
01217
01218
01219 a2dIterC ic( view );
01220 ic.SetDisableInvert( true );
01221
01222
01223 a2dAffineMatrix cworld= GetCanvasView()->GetShowObject()->GetTransformMatrix();
01224 cworld.Invert();
01225
01226 OVERLAP clipparent = _IN;
01227 ic.SetObjectFilter( new a2dCanvasObjectFilterToolObjects( a2dCanvasObject::PROPID_ToolObject, a2dCanvasOFlags::VISIBLE ) );
01228 ic.SetLayer( wxLAYER_ALL );
01229
01230 for( a2dCanvasObjectList::iterator iter = m_copies.begin(); iter != m_copies.end(); ++iter )
01231 {
01232 a2dCanvasObject *copy = *iter;
01233 a2dIterCU cu( ic, cworld );
01234 ic.GetDrawer2D()->SetDisableDrawing( true );
01235 copy->SetHasToolObjectsBelow(true);
01236 copy->Render( ic, clipparent );
01237 ic.Reset();
01238 ic.GetDrawer2D()->SetDisableDrawing( false );
01239 }
01240
01241 if ( m_anotate )
01242 {
01243 dcdrawer->DeviceDrawAnnotation( m_anotation, m_xanotation, m_yanotation, m_annotateFont );
01244 }
01245
01246 dcdrawer->EndDraw();
01247 dcdrawer->OverRuleFixedStyle();
01248 dcdrawer->SetRenderDC(NULL);
01249 delete dc;
01250 view->SetClosed();
01251 }
01252 }
01253
01254 void a2dFastDragMultiTool::AdjustShift( double *WXUNUSED(dx), double *WXUNUSED(dy) )
01255 {
01256 }
01257
01258 bool a2dFastDragMultiTool::CreateToolObjects()
01259 {
01260 m_objects.AssertUnique();
01261
01262 a2dCanvasObjectList::iterator iter;
01263
01264 for( iter = m_objects.begin(); iter != m_objects.end(); ++iter )
01265 {
01266 a2dCanvasObjectPtr original = *iter;
01267 a2dCanvasObject *copy = original->TClone( clone_flat );
01268
01269 a2dCanvasObject::PROPID_ToolObject->SetPropertyToObject( copy, this );
01270
01271
01272 m_copies.push_back( copy );
01273 copy->SetSelected( false );
01274
01275 if( original == m_original )
01276 m_canvasobject = copy;
01277 }
01278
01279 m_pending = true;
01280
01281 return true;
01282 }
01283
01284 void a2dFastDragMultiTool::CleanupToolObjects()
01285 {
01286 a2dStTool::CleanupToolObjects();
01287
01288 m_copies.clear();
01289 }
01290
01291
01292 void a2dFastDragMultiTool::OnIdle( wxIdleEvent &event )
01293 {
01294 if ( m_canvasobject && m_pending && GetBusy())
01295 {
01296 m_pending = false;
01297
01298 }
01299 else
01300 event.Skip();
01301 }
01302
01303 void a2dFastDragMultiTool::GenerateAnotation()
01304 {
01305 if ( m_anotate )
01306 {
01307 m_anotation.Printf( _T("x %6.3f y %6.3f"), m_canvasobject->GetPosX(), m_canvasobject->GetPosY() );
01308 wxCoord w, h, descent, external;
01309 GetTextExtent( m_anotation, &w, &h, &descent, &external );
01310 m_xanotation = m_x + h;
01311 m_yanotation = m_y + h;
01312
01313 GetDrawer2D()->DeviceDrawAnnotation( m_anotation, m_prevxanotation, m_prevyanotation, m_annotateFont );
01314
01315 GetDrawer2D()->DeviceDrawAnnotation( m_anotation, m_xanotation, m_yanotation, m_annotateFont );
01316
01317 m_prevxanotation = m_xanotation;
01318 m_prevyanotation = m_yanotation;
01319 }
01320 }
01321
01322 void a2dFastDragMultiTool::SetMode( int mode )
01323 {
01324 m_mode = mode;
01325 if (m_mode > 2) m_mode = 0;
01326
01327 if (!m_canvasobject)
01328 return;
01329
01330 m_pending = true;
01331 }
01332
01333 A2D_BEGIN_EVENT_TABLE(a2dFastCopyMultiTool,a2dFastDragMultiTool)
01334 A2D_EVT_CHAR(a2dFastCopyMultiTool::OnChar)
01335 A2D_EVT_MOUSE_EVENTS(a2dFastCopyMultiTool::OnMouseEvent)
01336 A2D_END_EVENT_TABLE()
01337
01338 a2dFastCopyMultiTool::a2dFastCopyMultiTool(a2dStToolContr* controller):a2dFastDragMultiTool(controller)
01339 {
01340 m_mindist = GetDrawer2D()->DeviceToWorldXRel( 5 );
01341 }
01342
01343 void a2dFastCopyMultiTool::OnChar(wxKeyEvent& event)
01344 {
01345 if (GetBusy())
01346 {
01347 switch(event.GetKeyCode())
01348 {
01349 case WXK_SPACE:
01350 {
01351 }
01352 break;
01353 default:
01354 event.Skip();
01355 }
01356 }
01357 else
01358 event.Skip();
01359
01360 }
01361
01362 void a2dFastCopyMultiTool::OnMouseEvent(wxMouseEvent& event)
01363 {
01364 if (!m_active)
01365 {
01366 event.Skip();
01367 return;
01368 }
01369
01370 m_x = event.GetX();
01371 m_y = event.GetY();
01372 MouseToToolWorld( m_x, m_y, m_xwprev, m_ywprev );
01373
01374 a2dRestrictionEngine *restrict = a2dCanvasGlobals->GetRestrictionEngine();
01375 if(restrict)
01376 {
01377 restrict->SetShiftKeyDown( event.ShiftDown() );
01378 restrict->SetAltKeyDown( event.AltDown() );
01379 restrict->RestrictPoint(m_xwprev, m_ywprev);
01380 }
01381
01382 if (event.LeftDown())
01383 {
01384 m_original = GetCanvasView()->IsHitWorld( m_xwprev, m_ywprev, wxLAYER_ALL, a2dCANOBJHITOPTION_LAYERS, true );
01385
01386 if (!m_original || !m_original->IsSelected() || !m_original->GetDraggable() )
01387 {
01388 m_original=0;
01389 return;
01390 }
01391
01392
01393
01394 OpenCommandGroup( false );
01395
01396
01397 GetCanvasView()->GetShowObject()->CollectObjects( &m_objects,_T(""),a2dCanvasOFlags::SELECTED );
01398
01399 EnterBusyMode();
01400 GetCanvasView()->Freeze();
01401 SetIgnorePendingObjects( true );
01402
01403 m_startMousexw = m_xwprev;
01404 m_startMouseyw = m_ywprev;
01405 m_startObjectx = m_original->GetPosX();
01406 m_startObjecty = m_original->GetPosY();
01407
01408
01409 {
01410 double dxm = m_xwprev-m_startMousexw;
01411 double dym = m_ywprev-m_startMouseyw;
01412 AdjustShift( &dxm, &dym );
01413
01414
01415 double dx = m_canvasobject->GetPosX();
01416 double dy = m_canvasobject->GetPosY();
01417 m_canvasobject->SetPosXY( dxm+m_startObjectx, dym+m_startObjecty );
01418 dx = m_canvasobject->GetPosX() - dx;
01419 dy = m_canvasobject->GetPosY() - dy;
01420 DragRelative( dx, dy );
01421 }
01422 m_pending = true;
01423 }
01424 else if (event.LeftUp() && GetBusy() )
01425 {
01426 event.Skip();
01427 }
01428 else if ( GetBusy() )
01429 {
01430 event.Skip();
01431 }
01432 else
01433 {
01434 event.Skip();
01435 }
01436 }
01437
01438 void a2dFastCopyMultiTool::AdjustShift( double *dx, double *dy )
01439 {
01440 if( (*dx)*(*dx)+(*dy)*(*dy)<m_mindist )
01441 {
01442 if( (*dx) == 0 && (*dy) == 0 )
01443 {
01444 (*dx) = m_mindist * 1.0;
01445 (*dy) = m_mindist * 0.5;
01446 }
01447 else
01448 {
01449 double fac = m_mindist / sqrt((*dx)*(*dx)+(*dy)*(*dy));
01450 (*dx)*=fac;
01451 (*dy)*=fac;
01452 }
01453 }
01454 }
01455
01456 void a2dFastCopyMultiTool::FinishBusyMode()
01457 {
01458 ReleaseMouse();
01459
01460 double dx = m_canvasobject->GetPosX() - m_startObjectx;
01461 double dy = m_canvasobject->GetPosY() - m_startObjecty;
01462
01463 GetCanvasCommandProcessor()->Submit( new a2dCommand_CopyMask( dx, dy) );
01464 a2dCanvasObjectList::iterator iter;
01465 for( iter = m_objects.begin(); iter != m_objects.end(); ++iter )
01466 {
01467 a2dCanvasObject *obj = *iter;
01468
01469 obj->SetPending( true );
01470 GetCanvasCommandProcessor()->Submit( new a2dCommand_SetFlag( obj, a2dCanvasOFlags::SELECTED, false ), true );
01471 }
01472 m_objects.clear();
01473 a2dStTool::FinishBusyMode();
01474 }
01475
01476
01477
01478
01479
01480 IMPLEMENT_CLASS(a2dDrawRectangleToolFast, a2dStDrawToolFast)
01481
01482 A2D_BEGIN_EVENT_TABLE(a2dDrawRectangleToolFast,a2dStDrawToolFast)
01483 A2D_EVT_COM_EVENT( a2dDrawRectangleToolFast::OnComEvent )
01484 A2D_EVT_MOUSE_EVENTS(a2dDrawRectangleToolFast::OnMouseEvent)
01485 A2D_END_EVENT_TABLE()
01486
01487 a2dDrawRectangleToolFast::a2dDrawRectangleToolFast(a2dStToolContr* controller):a2dStDrawToolFast(controller)
01488 {
01489 m_radius = 0;
01490 SetFill( *a2dTRANSPARENT_FILL );
01491 SetStroke( a2dStroke(*wxBLACK, 2, a2dSTROKE_LONG_DASH) );
01492 m_xwlast = 0;
01493 m_ywlast = 0;
01494 m_didDraw = false;
01495 }
01496
01497 a2dDrawRectangleToolFast::~a2dDrawRectangleToolFast()
01498 {
01499 }
01500
01501 void a2dDrawRectangleToolFast::OnComEvent( a2dComEvent& event )
01502 {
01503 if ( GetBusy() &&
01504 event.GetEventComId() == &a2dStToolContr::sm_showCursor &&
01505 m_stcontroller->GetFrame() &&
01506 m_stcontroller->GetFrame()->GetStatusBar() )
01507 {
01508 double mouse_worldx = m_xwprev;
01509 double mouse_worldy = m_ywprev;
01510
01511 wxString unitmeasure = GetCanvasDocument()->GetUnits();
01512 double scaleToMeters = GetCanvasDocument()->GetUnitsScale();
01513
01514 double multi = 1;
01515 a2dDoMu::GetMultiplierFromString( unitmeasure, multi );
01516
01517 mouse_worldx *= scaleToMeters/multi;
01518 mouse_worldy *= scaleToMeters/multi;
01519
01520 a2dRect* rec = wxStaticCast( m_original.Get(), a2dRect );
01521 wxString str;
01522 str.Printf( _T("x=%6.3f, y=%6.3f, width=%6.3f, height=%6.3f"),
01523 mouse_worldx, mouse_worldy,
01524 rec->GetWidth(),rec->GetHeight() );
01525 str = str + _T(" ") + unitmeasure + _T(" :") + GetClassInfo()->GetClassName();
01526 m_stcontroller->GetFrame()->SetStatusText( str );
01527 }
01528 else
01529 event.Skip();
01530 }
01531
01532 void a2dDrawRectangleToolFast::OnMouseEvent(wxMouseEvent& event)
01533 {
01534 if (!m_active)
01535 {
01536 event.Skip();
01537 return;
01538 }
01539
01540 if ( GetBusy() )
01541 GetCanvasView()->SetCursor( m_toolBusyCursor );
01542 else
01543 GetCanvasView()->SetCursor( m_toolcursor );
01544
01545 m_x = event.GetX();
01546 m_y = event.GetY();
01547 MouseToToolWorld( m_x, m_y, m_xwprev, m_ywprev );
01548
01549 a2dRestrictionEngine *restrict = a2dCanvasGlobals->GetRestrictionEngine();
01550 if(restrict)
01551 {
01552 restrict->SetShiftKeyDown( event.ShiftDown() );
01553 restrict->SetAltKeyDown( event.AltDown() );
01554 restrict->RestrictPoint(m_xwprev, m_ywprev);
01555 }
01556
01557 double wr = GetDrawer2D()->DeviceToWorldXRel( 30 );
01558 if (event.LeftDown() && !GetBusy())
01559 {
01560 EnterBusyMode();
01561 }
01562 else if (event.LeftDown() && GetBusy())
01563 {
01564 a2dRect* rec = wxStaticCast( m_original.Get(), a2dRect );
01565 a2dDocviewGlobals->RecordF( this, _T("rect %f %f %f %f"), rec->GetPosX(), rec->GetPosY(), rec->GetWidth(), rec->GetHeight() );
01566 FinishBusyMode();
01567 }
01568 else if ((event.Dragging()&& GetBusy()) || (event.Moving() && GetBusy()) )
01569 {
01570 a2dRect* rec = wxStaticCast( m_canvasobject.Get(), a2dRect );
01571
01572 rec->SetWidth( m_xwprev - rec->GetPosX() );
01573 rec->SetHeight( m_ywprev - rec->GetPosY() );
01574 a2dCanvasObject::SetIgnoreAllSetpending( true );
01575 a2dRect* recorg = wxStaticCast( m_original.Get(), a2dRect );
01576 recorg->SetWidth( rec->GetWidth() );
01577 recorg->SetHeight( rec->GetHeight() );
01578 a2dCanvasObject::SetIgnoreAllSetpending( false );
01579 }
01580 else if ( !GetBusy() )
01581 {
01582 event.Skip();
01583 }
01584 else
01585 event.Skip();
01586 }
01587
01588 bool a2dDrawRectangleToolFast::CreateToolObjects()
01589 {
01590 a2dRect* rec = new a2dRect( m_xwprev, m_ywprev, 0, 0, m_radius);
01591 m_original = rec;
01592 rec->SetFill( m_fill );
01593 rec->SetStroke( m_stroke );
01594
01595 return a2dStDrawToolFast::CreateToolObjects();
01596 }
01597
01598
01599
01600
01601
01602 IMPLEMENT_CLASS(a2dDrawCircleToolFast, a2dStDrawToolFast)
01603
01604 A2D_BEGIN_EVENT_TABLE(a2dDrawCircleToolFast,a2dStDrawToolFast)
01605 A2D_EVT_COM_EVENT( a2dDrawCircleToolFast::OnComEvent )
01606 A2D_EVT_CHAR( a2dDrawCircleToolFast::OnChar )
01607 A2D_EVT_MOUSE_EVENTS( a2dDrawCircleToolFast::OnMouseEvent )
01608 A2D_END_EVENT_TABLE()
01609
01610 a2dDrawCircleToolFast::a2dDrawCircleToolFast(a2dStToolContr* controller):a2dStDrawToolFast(controller)
01611 {
01612 m_toolcursor = a2dCanvasGlobals->GetCursor( a2dCURSOR_PENCIL );
01613 m_toolBusyCursor = a2dCanvasGlobals->GetCursor( a2dCURSOR_CROSS );
01614 }
01615
01616 void a2dDrawCircleToolFast::OnComEvent( a2dComEvent& event )
01617 {
01618 if ( GetBusy() &&
01619 event.GetEventComId() == &a2dStToolContr::sm_showCursor &&
01620 m_stcontroller->GetFrame() &&
01621 m_stcontroller->GetFrame()->GetStatusBar() )
01622 {
01623 double mouse_worldx = m_xwprev;
01624 double mouse_worldy = m_ywprev;
01625
01626 wxString unitmeasure = GetCanvasDocument()->GetUnits();
01627 double scaleToMeters = GetCanvasDocument()->GetUnitsScale();
01628
01629 double multi = 1;
01630 a2dDoMu::GetMultiplierFromString( unitmeasure, multi );
01631
01632 mouse_worldx *= scaleToMeters/multi;
01633 mouse_worldy *= scaleToMeters/multi;
01634
01635 a2dCircle* cir = wxStaticCast( m_original.Get(), a2dCircle );
01636 wxString str;
01637 str.Printf( _T("x=%6.3f, y=%6.3f, radius=%6.3f"), mouse_worldx, mouse_worldy, cir->GetRadius() );
01638 str = str + _T(" ") + unitmeasure + _T(" :") + GetClassInfo()->GetClassName();
01639 m_stcontroller->GetFrame()->SetStatusText( str );
01640 }
01641 else
01642 event.Skip();
01643 }
01644
01645
01646 void a2dDrawCircleToolFast::OnChar(wxKeyEvent& event)
01647 {
01648 if (GetBusy())
01649 {
01650 switch(event.GetKeyCode())
01651 {
01652 case WXK_TAB:
01653 {
01654 m_mode++;
01655 }
01656 break;
01657
01658 default:
01659 event.Skip();
01660 }
01661 }
01662 else
01663 event.Skip();
01664
01665 }
01666
01667 void a2dDrawCircleToolFast::SetMode( int mode )
01668 {
01669 m_mode = mode;
01670 if (m_mode > 2) m_mode = 0;
01671
01672 if (!m_canvasobject)
01673 return;
01674
01675 a2dCircle* cir = wxStaticCast( m_canvasobject.Get(), a2dCircle );
01676 a2dCircle* cirorg = wxStaticCast( m_original.Get(), a2dCircle );
01677 switch ( m_mode )
01678 {
01679 case 0:
01680 {
01681 double dx, dy;
01682
01683 if ( fabs( m_xwprev - m_start_x ) > fabs( m_ywprev - m_start_y ) )
01684 {
01685 dx = ( m_xwprev - m_start_x ) /2 ;
01686 m_radius = fabs( dx );
01687 if ( m_ywprev > m_start_y )
01688 dy = m_radius;
01689 else
01690 dy = -m_radius;
01691 }
01692 else
01693 {
01694 dy = ( m_ywprev - m_start_y ) /2 ;
01695 m_radius = fabs( dy );
01696 if ( m_xwprev > m_start_x )
01697 dx = m_radius;
01698 else
01699 dx = -m_radius;
01700 }
01701 cir->SetPosXY( m_start_x + dx , m_start_y + dy );
01702 cirorg->SetPosXY( m_start_x + dx , m_start_y + dy );
01703 break;
01704 }
01705 case 1:
01706 {
01707 cir->SetPosXY( m_start_x, m_start_y );
01708 cirorg->SetPosXY( m_start_x, m_start_y );
01709 m_radius = sqrt(pow(m_xwprev-cir->GetPosX(),2)+pow(m_ywprev-cir->GetPosY(),2));
01710 break;
01711 }
01712 case 2:
01713 {
01714 cir->SetPosXY( (m_xwprev+m_start_x)/2, (m_ywprev+m_start_y)/2 );
01715 cirorg->SetPosXY( (m_xwprev+m_start_x)/2, (m_ywprev+m_start_y)/2 );
01716 m_radius = sqrt(pow(m_xwprev-m_start_x,2)+pow(m_ywprev-m_start_y,2))/2;
01717 break;
01718 }
01719 default:
01720 break;
01721 }
01722
01723 cir->SetRadius(m_radius);
01724 cirorg->SetRadius(m_radius);
01725 m_pending = true;
01726 }
01727
01728 void a2dDrawCircleToolFast::OnMouseEvent(wxMouseEvent& event)
01729 {
01730 if (!m_active)
01731 {
01732 event.Skip();
01733 return;
01734 }
01735
01736 if ( GetBusy() )
01737 GetCanvasView()->SetCursor( m_toolBusyCursor );
01738 else
01739 GetCanvasView()->SetCursor( m_toolcursor );
01740
01741 m_x = event.GetX();
01742 m_y = event.GetY();
01743 double newx, newy;
01744 MouseToToolWorld( m_x, m_y, newx, newy );
01745
01746 a2dRestrictionEngine *restrict = a2dCanvasGlobals->GetRestrictionEngine();
01747 if(restrict)
01748 {
01749 restrict->SetShiftKeyDown( event.ShiftDown() );
01750 restrict->SetAltKeyDown( event.AltDown() );
01751 restrict->RestrictPoint( newx, newy );
01752 }
01753
01754 if (event.LeftDown() && !GetBusy())
01755 {
01756 m_radius = 0;
01757 m_xwprev = newx;
01758 m_ywprev = newy;
01759 m_start_x = m_xwprev;
01760 m_start_y = m_ywprev;
01761 EnterBusyMode();
01762 }
01763 else if (event.LeftDown() && GetBusy())
01764 {
01765 a2dDocviewGlobals->RecordF( this, _T("circle %f %f %f"), m_original->GetPosX(), m_original->GetPosY(), m_radius );
01766
01767 FinishBusyMode();
01768 }
01769 else if ((event.Dragging()&& GetBusy()) || (event.Moving() && GetBusy()) )
01770 {
01771 m_xwprev = newx;
01772 m_ywprev = newy;
01773 a2dCanvasObject::SetIgnoreAllSetpending( true );
01774 SetMode( m_mode );
01775 a2dCanvasObject::SetIgnoreAllSetpending( false );
01776 m_canvasobject->SetPending( true );
01777 }
01778 else
01779 event.Skip();
01780 }
01781
01782 bool a2dDrawCircleToolFast::CreateToolObjects()
01783 {
01784 m_original = new a2dCircle( m_xwprev, m_ywprev, m_radius);
01785 m_original->SetFill( m_fill );
01786 m_original->SetStroke( m_stroke );
01787
01788 return a2dStDrawToolFast::CreateToolObjects();
01789 }
01790
01791 IMPLEMENT_CLASS(a2dDrawPolygonLToolFast, a2dStDrawToolFast)
01792
01793 A2D_BEGIN_EVENT_TABLE(a2dDrawPolygonLToolFast,a2dStDrawToolFast)
01794 A2D_EVT_IDLE( a2dDrawPolygonLToolFast::OnIdle )
01795 A2D_EVT_CHAR( a2dDrawPolygonLToolFast::OnChar )
01796 A2D_EVT_MOUSE_EVENTS(a2dDrawPolygonLToolFast::OnMouseEvent)
01797 A2D_EVT_UNDO( a2dDrawPolygonLToolFast::OnUndoEvent )
01798 A2D_EVT_REDO( a2dDrawPolygonLToolFast::OnRedoEvent )
01799 A2D_END_EVENT_TABLE()
01800
01801 void a2dDrawPolygonLToolFast::AddPoint( a2dLineSegment* point )
01802 {
01803 if ( m_reverse )
01804 m_points->push_front(point);
01805 else
01806 m_points->push_back(point);
01807 }
01808
01809 a2dDrawPolygonLToolFast::a2dDrawPolygonLToolFast(a2dStToolContr* controller, a2dPolygonL* templateObject ):a2dStDrawToolFast(controller)
01810 {
01811 m_toolcursor = a2dCanvasGlobals->GetCursor( a2dCURSOR_PENCIL );
01812 m_toolBusyCursor = a2dCanvasGlobals->GetCursor( a2dCURSOR_CROSS );
01813 m_contourwidth = a2dGetCmdh()->GetContourWidthInDataBaseUnits();
01814
01815 m_canvasobject = (a2dCanvasObject*)0;
01816 m_points = (a2dVertexList*) 0;
01817
01818 m_spline = a2dGetCmdh()->GetSpline();
01819 m_reverse = false;
01820
01821 m_templateObject = templateObject;
01822 if ( templateObject )
01823 m_spline = m_templateObject->GetSpline();
01824 }
01825
01826 a2dDrawPolygonLToolFast::~a2dDrawPolygonLToolFast()
01827 {
01828 }
01829
01830 void a2dDrawPolygonLToolFast::SetSpline(bool spline)
01831 {
01832 m_spline = spline;
01833 }
01834
01835 void a2dDrawPolygonLToolFast::OnIdle( wxIdleEvent &event )
01836 {
01837 if (m_pending && GetBusy())
01838 {
01839 RemoveAllDecorations();
01840
01841 a2dPolygonL* poly = wxStaticCast( m_canvasobject.Get(), a2dPolygonL );
01842 a2dRect* around = NULL;
01843 a2dPolygonL* nonSplined = NULL;
01844
01845 switch ( m_mode )
01846 {
01847 case 2:
01848 {
01849
01850 if ( poly->GetSpline() )
01851 {
01852 nonSplined = (a2dPolygonL*) poly->TClone( clone_childs );
01853 nonSplined->SetVisible( true );
01854 nonSplined->SetSpline( false );
01855 nonSplined->SetFill( *a2dTRANSPARENT_FILL );
01856
01857 nonSplined->SetStroke( *wxBLACK, 0, a2dSTROKE_DOT_DASH );
01858 AddDecorationObject( nonSplined );
01859
01860 }
01861 }
01862 case 1:
01863 {
01864 around = new a2dRect( poly->GetBboxMinX(), poly->GetBboxMinY(), poly->GetBboxWidth(), poly->GetBboxHeight() );
01865 around->SetStroke( *wxRED, 0, a2dSTROKE_DOT_DASH );
01866 around->SetFill( *a2dTRANSPARENT_FILL );
01867 around->SetCanvasDocument( GetCanvasView()->GetCanvasDocument() );
01868 AddDecorationObject( around );
01869 break;
01870 }
01871 default:
01872 break;
01873 }
01874
01875 event.Skip();
01876 }
01877 else
01878 event.Skip();
01879 }
01880
01881 void a2dDrawPolygonLToolFast::OnUndoEvent( a2dCommandProcessorEvent& event )
01882 {
01883 static long lastProcessedEventTimeStamp = -1;
01884 if( lastProcessedEventTimeStamp == event.GetTimestamp() )
01885 return;
01886 lastProcessedEventTimeStamp = event.GetTimestamp();
01887
01888 if (GetBusy() && !m_halted)
01889 {
01890
01891
01892 a2dPolygonL* poly = wxStaticCast( m_original.Get(), a2dPolygonL );
01893 if ( poly->GetNumberOfSegments() )
01894 {
01895 a2dLineSegmentPtr lastpoint = poly->GetSegments()->back();
01896 CleanupToolObjects();
01897 GetCanvasView()->Update( a2dCANVIEW_UPDATE_OLDNEW );
01898 CreateToolObjects();
01899 m_points = wxStaticCast( m_canvasobject.Get(), a2dPolygonL )->GetSegments();
01900 m_point = lastpoint;
01901 m_points->push_back( m_point );
01902 }
01903 }
01904 }
01905
01906 void a2dDrawPolygonLToolFast::OnRedoEvent( a2dCommandProcessorEvent& event )
01907 {
01908 OnUndoEvent( event );
01909 }
01910
01911 void a2dDrawPolygonLToolFast::SetMode( int mode )
01912 {
01913 m_mode = mode;
01914 if (m_mode > 2) m_mode = 0;
01915
01916 if (!m_canvasobject)
01917 return;
01918
01919 m_pending = true;
01920 }
01921
01922 void a2dDrawPolygonLToolFast::OnChar(wxKeyEvent& event)
01923 {
01924 if (GetBusy() && m_canvasobject)
01925 {
01926 double shiftx;
01927 double shifty;
01928 GetKeyIncrement(&shiftx, &shifty, event.AltDown());
01929
01930 switch(event.GetKeyCode())
01931 {
01932 case WXK_TAB:
01933 {
01934 m_mode++;
01935 SetMode( m_mode );
01936 }
01937 break;
01938
01939 case WXK_UP:
01940 shiftx = 0;
01941 break;
01942
01943 case WXK_DOWN:
01944 shiftx = 0;
01945 shifty = -shifty;
01946 break;
01947
01948 case WXK_LEFT:
01949 shiftx = -shiftx;
01950 shifty = 0;
01951 break;
01952
01953 case WXK_RIGHT:
01954 shifty = 0;
01955 break;
01956
01957 default:
01958 {
01959 shiftx = 0;
01960 shifty = 0;
01961 event.Skip();
01962 }
01963 }
01964
01965 if ( event.m_controlDown )
01966 {
01967 m_point->m_x += shiftx;
01968 m_point->m_y += shifty;
01969 }
01970 else
01971 {
01972 double x = m_canvasobject->GetPosX();
01973 double y = m_canvasobject->GetPosY();
01974 m_canvasobject->SetPosXY( x + shiftx, y + shifty, true );
01975 a2dPolygonL* poly = wxStaticCast( m_canvasobject.Get(), a2dPolygonL );
01976 poly->EliminateMatrix();
01977 }
01978
01979 GetDisplayWindow()->WarpPointer( GetDrawer2D()->WorldToDeviceX( m_point->m_x ), GetDrawer2D()->WorldToDeviceY( m_point->m_y ) );
01980
01981 m_pending = true;
01982 }
01983 else
01984 event.Skip();
01985
01986 }
01987
01988 void a2dDrawPolygonLToolFast::OnMouseEvent(wxMouseEvent& event)
01989 {
01990 if (!m_active)
01991 {
01992 event.Skip();
01993 return;
01994 }
01995
01996 if ( GetBusy() )
01997 GetCanvasView()->SetCursor( m_toolBusyCursor );
01998 else
01999 GetCanvasView()->SetCursor( m_toolcursor );
02000
02001 m_x = event.GetX();
02002 m_y = event.GetY();
02003
02004 a2dRestrictionEngine *restrict = a2dCanvasGlobals->GetRestrictionEngine();
02005 if (event.LeftDown() && !GetBusy())
02006 {
02007 SetIgnorePendingObjects( true );
02008 MouseToToolWorld( m_x, m_y, m_xwprev, m_ywprev );
02009 if(restrict)
02010 {
02011 restrict->SetShiftKeyDown( event.ShiftDown() );
02012 restrict->SetAltKeyDown( event.AltDown() );
02013 restrict->RestrictPoint(m_xwprev, m_ywprev);
02014 }
02015 a2dGetCmdh()->SetLastXyEntry( m_xwprev, m_ywprev );
02016
02017 if ( m_templateObject )
02018 {
02019 m_original = m_templateObject->TClone( clone_childs );
02020 m_original->Translate( m_xwprev, m_ywprev );
02021 m_original->EliminateMatrix();
02022 }
02023 else
02024 {
02025 m_original = new a2dPolygonL( new a2dVertexList(), m_spline );
02026 m_original->SetStroke( m_stroke );
02027 m_original->SetFill( m_fill );
02028 m_original->SetLayer(m_layer);
02029 }
02030
02031 EnterBusyMode();
02032
02033
02034 GetCanvasCommandProcessor()->Submit(
02035 new a2dCommand_AddPoint( m_original, m_xwprev, m_ywprev, -1 )
02036 );
02037
02038 m_points = wxStaticCast( m_canvasobject.Get(), a2dPolygonL )->GetSegments();
02039 m_point = new a2dLineSegment(m_xwprev,m_ywprev);
02040 m_points->push_back(m_point);
02041
02042
02043 a2dDocviewGlobals->RecordF( this, _T("polygon") );
02044 a2dDocviewGlobals->RecordF( this, _T("addpoint %f %f"), m_xwprev, m_ywprev );
02045
02046
02047 m_point = new a2dLineSegment(m_xwprev,m_ywprev);
02048 m_points->push_back(m_point);
02049
02050 m_prev_x = m_xwprev;
02051 m_prev_y = m_ywprev;
02052 m_pending = true;
02053 if(restrict)
02054 restrict->SetRestrictPoint( m_xwprev, m_ywprev );
02055 }
02056 else if (event.LeftDown() && GetBusy())
02057 {
02058 MouseToToolWorld( m_x, m_y, m_xwprev, m_ywprev );
02059 if(restrict)
02060 restrict->RestrictPoint(m_xwprev, m_ywprev);
02061
02062 a2dGetCmdh()->SetLastXyEntry( m_xwprev, m_ywprev );
02063 int x = GetDrawer2D()->WorldToDeviceX(m_prev_x);
02064 int y = GetDrawer2D()->WorldToDeviceY(m_prev_y);
02065 if (abs(m_x-x) >=3 || abs(m_y-y) >= 3)
02066 {
02067 GetCanvasCommandProcessor()->Submit(
02068 new a2dCommand_AddPoint( m_original, m_xwprev, m_ywprev, -1 )
02069 );
02070
02071 a2dDocviewGlobals->RecordF( this, _T("addpoint %f %f "), m_xwprev, m_ywprev );
02072
02073 m_point = new a2dLineSegment(m_xwprev,m_ywprev);
02074 m_points->push_back(m_point);
02075 m_prev_x = m_xwprev;
02076 m_prev_y = m_ywprev;
02077 }
02078 if(restrict)
02079 restrict->SetRestrictPoint( m_xwprev, m_ywprev );
02080 }
02081 else if (event.Moving() && GetBusy())
02082 {
02083 SetMode( m_mode );
02084
02085 MouseToToolWorld( m_x, m_y, m_xwprev, m_ywprev );
02086 if(restrict)
02087 restrict->RestrictPoint(m_xwprev, m_ywprev);
02088 m_point->m_x = m_xwprev;
02089 m_point->m_y = m_ywprev;
02090 m_canvasobject->SetPending( true );
02091
02092 event.Skip();
02093 }
02094 else if (event.LeftDClick() && GetBusy())
02095 {
02096 MouseToToolWorld( m_x, m_y, m_xwprev, m_ywprev );
02097 if(restrict)
02098 restrict->RestrictPoint(m_xwprev, m_ywprev);
02099 a2dGetCmdh()->SetLastXyEntry( m_xwprev, m_ywprev );
02100 a2dDocviewGlobals->RecordF( this, _T("end") );
02101 FinishBusyMode();
02102 }
02103 else
02104 event.Skip();
02105 }
02106
02107 bool a2dDrawPolygonLToolFast::CreateToolObjects()
02108 {
02109 return a2dStDrawToolFast::CreateToolObjects();
02110 }
02111
02112 IMPLEMENT_CLASS(a2dDrawPolylineLToolFast, a2dDrawPolygonLToolFast)
02113
02114 A2D_BEGIN_EVENT_TABLE( a2dDrawPolylineLToolFast,a2dDrawPolygonLToolFast )
02115 A2D_EVT_MOUSE_EVENTS( a2dDrawPolylineLToolFast::OnMouseEvent )
02116 A2D_EVT_DO( a2dDrawPolylineLToolFast::OnDoEvent )
02117 A2D_END_EVENT_TABLE()
02118
02119 a2dDrawPolylineLToolFast::a2dDrawPolylineLToolFast(a2dStToolContr* controller, a2dPolylineL* templateObject ):
02120 a2dDrawPolygonLToolFast( controller, templateObject )
02121 {
02122 m_xscale = 1;
02123 m_yscale = 1;
02124 m_begin = 0;
02125 m_end = 0;
02126 m_pathtype = a2dGetCmdh()->GetPathType();
02127 m_contourwidth = a2dGetCmdh()->GetContourWidthInDataBaseUnits();
02128 }
02129
02130 a2dDrawPolylineLToolFast::~a2dDrawPolylineLToolFast()
02131 {
02132 }
02133
02134 void a2dDrawPolylineLToolFast::SetPathType( a2dPATH_END_TYPE pathtype )
02135 {
02136 if ( GetBusy() )
02137 {
02138 a2dPolylineL* poly = wxStaticCastNull( m_canvasobject.Get(), a2dPolylineL );
02139 poly->SetPathType( m_pathtype );
02140 a2dPolylineL* polyorg = wxStaticCastNull( m_original.Get(), a2dPolylineL );
02141 polyorg->SetPathType( m_pathtype );
02142 }
02143
02144 m_pathtype = pathtype;
02145 }
02146
02147 void a2dDrawPolylineLToolFast::SetLineBegin(a2dCanvasObject* begin)
02148 {
02149 if ( GetBusy() )
02150 {
02151 a2dPolylineL* poly = wxStaticCastNull( m_canvasobject.Get(), a2dPolylineL );
02152 poly->SetEndScaleX( m_yscale );
02153 poly->SetEndScaleY( m_xscale );
02154 poly->SetBegin( begin );
02155 a2dPolylineL* polyorg = wxStaticCastNull( m_original.Get(), a2dPolylineL );
02156 polyorg->SetEndScaleX( m_yscale );
02157 polyorg->SetEndScaleY( m_xscale );
02158 polyorg->SetBegin( begin );
02159 }
02160 m_begin = begin;
02161 }
02162
02163 void a2dDrawPolylineLToolFast::SetLineEnd(a2dCanvasObject* end)
02164 {
02165 if ( GetBusy() )
02166 {
02167 a2dPolylineL* poly = wxStaticCastNull( m_canvasobject.Get(), a2dPolylineL );
02168 poly->SetEndScaleX( m_yscale );
02169 poly->SetEndScaleY( m_xscale );
02170 poly->SetEnd( end );
02171 a2dPolylineL* polyorg = wxStaticCastNull( m_original.Get(), a2dPolylineL );
02172 polyorg->SetEndScaleX( m_yscale );
02173 polyorg->SetEndScaleY( m_xscale );
02174 polyorg->SetEnd( end );
02175 }
02176 m_end = end;
02177 }
02178
02179 void a2dDrawPolylineLToolFast::OnDoEvent( a2dCommandProcessorEvent& event )
02180 {
02181 if ( !m_templateObject )
02182 {
02183 if ( event.GetCommand()->GetCommandId() == &a2dCommand_SetContourWidth::Id )
02184 {
02185 m_contourwidth = a2dGetCmdh()->GetContourWidthInDataBaseUnits();
02186 if ( GetBusy() )
02187 {
02188 m_canvasobject->SetContourWidth( m_contourwidth );
02189 m_original->SetContourWidth( m_contourwidth );
02190 }
02191 }
02192 if ( event.GetCommand()->GetCommandId() == &a2dCommand_SetPathType::Id )
02193 {
02194 m_pathtype = a2dGetCmdh()->GetPathType();
02195 if ( GetBusy() )
02196 {
02197 a2dPolylineL* poly = wxStaticCast( m_original.Get(), a2dPolylineL );
02198 poly->SetPathType( m_pathtype );
02199 poly = wxStaticCast( m_canvasobject.Get(), a2dPolylineL );
02200 poly->SetPathType( m_pathtype );
02201 }
02202 }
02203 }
02204 }
02205
02206 void a2dDrawPolylineLToolFast::OnMouseEvent(wxMouseEvent& event)
02207 {
02208 if (!m_active)
02209 {
02210 event.Skip();
02211 return;
02212 }
02213
02214 if ( GetBusy() )
02215 GetCanvasView()->SetCursor( m_toolBusyCursor );
02216 else
02217 GetCanvasView()->SetCursor( m_toolcursor );
02218
02219 m_x = event.GetX();
02220 m_y = event.GetY();
02221 MouseToToolWorld( m_x, m_y, m_xwprev, m_ywprev );
02222
02223 a2dRestrictionEngine *restrict = a2dCanvasGlobals->GetRestrictionEngine();
02224 if (event.LeftDown() && !GetBusy())
02225 {
02226 SetIgnorePendingObjects( true );
02227 MouseToToolWorld( m_x, m_y, m_xwprev, m_ywprev );
02228
02229 if(restrict)
02230 {
02231 restrict->SetShiftKeyDown( event.ShiftDown() );
02232 restrict->SetAltKeyDown( event.AltDown() );
02233 restrict->RestrictPoint(m_xwprev, m_ywprev);
02234 }
02235 a2dGetCmdh()->SetLastXyEntry( m_xwprev, m_ywprev );
02236
02237 if ( m_templateObject )
02238 {
02239 m_original = m_templateObject->TClone( clone_childs | clone_members );
02240 m_original->Translate( m_xwprev, m_ywprev );
02241 m_original->EliminateMatrix();
02242 }
02243 else
02244 {
02245 m_original = new a2dPolylineL( new a2dVertexList(), m_spline );
02246 m_original->SetContourWidth( m_contourwidth );
02247 m_original->SetStroke( m_stroke );
02248 m_original->SetFill( m_fill );
02249 m_original->SetLayer( m_layer );
02250 a2dPolylineL* poly = wxStaticCast( m_original.Get(), a2dPolylineL );
02251 poly->SetPathType( m_pathtype );
02252 if ( m_begin || m_end )
02253 {
02254 poly->SetEndScaleX( m_yscale );
02255 poly->SetEndScaleY( m_xscale );
02256
02257
02258 if ( m_begin )
02259 poly->SetBegin( m_begin->TClone( clone_flat ) );
02260 if ( m_end )
02261 poly->SetEnd( m_end->TClone( clone_flat ) );
02262 }
02263 }
02264
02265 EnterBusyMode();
02266 m_canvasobject->SetContourWidth( m_contourwidth );
02267 a2dPolylineL* poly = wxStaticCast( m_canvasobject.Get(), a2dPolylineL );
02268 poly->SetPathType( m_pathtype );
02269
02270 m_points = poly->GetSegments();
02271
02272 a2dDocviewGlobals->RecordF( this, _T("polyline") );
02273
02274 m_canvasobject->SetCanvasDocument( GetCanvasDocument() );
02275
02276
02277 if ( m_reverse )
02278 GetCanvasCommandProcessor()->Submit(
02279 new a2dCommand_AddPoint( m_original, m_xwprev, m_ywprev, 0 )
02280 );
02281 else
02282 GetCanvasCommandProcessor()->Submit(
02283 new a2dCommand_AddPoint( m_original, m_xwprev, m_ywprev, -1 )
02284 );
02285
02286 m_point = new a2dLineSegment( m_xwprev,m_ywprev);
02287 AddPoint( m_point );
02288
02289 a2dDocviewGlobals->RecordF( this, _T("addpoint %f %f "), m_xwprev, m_ywprev );
02290
02291
02292 m_point = new a2dLineSegment(m_xwprev,m_ywprev);
02293 AddPoint( m_point );
02294
02295 m_prev_x = m_xwprev;
02296 m_prev_y = m_ywprev;
02297
02298 if(restrict)
02299 restrict->SetRestrictPoint( m_xwprev, m_ywprev );
02300 }
02301 else if (event.Moving() && GetBusy())
02302 {
02303 SetMode( m_mode );
02304
02305 MouseToToolWorld( m_x, m_y, m_xwprev, m_ywprev );
02306 if(restrict)
02307 restrict->RestrictPoint(m_xwprev, m_ywprev);
02308 m_point->m_x = m_xwprev;
02309 m_point->m_y = m_ywprev;
02310 m_canvasobject->SetPending( true );
02311 }
02312 else
02313 event.Skip();
02314 }
02315
02316 bool a2dDrawPolylineLToolFast::CreateToolObjects()
02317 {
02318 return a2dStDrawToolFast::CreateToolObjects();
02319 }