From a40252f16bec66a1b952c3e15ee0fcdc591d892e Mon Sep 17 00:00:00 2001 From: asl Date: Mon, 11 Aug 2014 12:36:08 +0000 Subject: [PATCH] refs #369: local coords with image --- src/HYDROData/HYDROData_Document.cxx | 22 ++++++++++++++++++++++ src/HYDROData/HYDROData_Document.h | 3 +++ src/HYDROGUI/HYDROGUI_Module.cxx | 22 ++++++++++++++++------ src/HYDROGUI/HYDROGUI_Shape.cxx | 6 ++++++ src/HYDROGUI/resources/HYDROGUI_msg_en.ts | 5 ++++- 5 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/HYDROData/HYDROData_Document.cxx b/src/HYDROData/HYDROData_Document.cxx index 788b5527..3a460435 100644 --- a/src/HYDROData/HYDROData_Document.cxx +++ b/src/HYDROData/HYDROData_Document.cxx @@ -638,12 +638,16 @@ HYDROData_Document::HYDROData_Document() myDoc->SetUndoLimit(UNDO_LIMIT); NewID(); // needed to have at least one attribute in initial document to avoid errors myTransactionsAfterSave = 0; + myLX = -1; + myLY = -1; } HYDROData_Document::HYDROData_Document(const Handle(TDocStd_Document)& theDoc) { myDoc = theDoc; myTransactionsAfterSave = 0; + myLX = -1; + myLY = -1; } HYDROData_Document::~HYDROData_Document() @@ -697,4 +701,22 @@ void HYDROData_Document::SetLocalCS( const gp_Pnt2d& theLocalCS ) gp_Pnt aLocalCS3d( theLocalCS.X(), theLocalCS.Y(), 0 ); aLocalCS->SetPosition( aLocalCS3d ); + myLX = theLocalCS.X(); + myLY = theLocalCS.Y(); } + +void HYDROData_Document::Transform( gp_Pnt& thePnt, bool IsToLocalCS ) const +{ + if( myLX < 0 || myLY < 0 ) + { + gp_Pnt2d aLCS = GetLocalCS(); + HYDROData_Document* aThat = const_cast( this ); + aThat->myLX = aLCS.X(); + aThat->myLY = aLCS.Y(); + } + double X = IsToLocalCS ? thePnt.X() - myLX : thePnt.X() + myLX; + double Y = IsToLocalCS ? thePnt.Y() - myLY : thePnt.Y() + myLY; + double Z = thePnt.Z(); + thePnt = gp_Pnt( X, Y, Z ); +} + diff --git a/src/HYDROData/HYDROData_Document.h b/src/HYDROData/HYDROData_Document.h index 2ed1acd7..7eeca638 100644 --- a/src/HYDROData/HYDROData_Document.h +++ b/src/HYDROData/HYDROData_Document.h @@ -8,6 +8,7 @@ class QFile; class gp_Pnt2d; +class gp_Pnt; /** * Errors that could appear on document open/save actions. @@ -126,6 +127,7 @@ public: HYDRODATA_EXPORT gp_Pnt2d GetLocalCS() const; HYDRODATA_EXPORT void SetLocalCS( const gp_Pnt2d& ); + HYDRODATA_EXPORT void Transform( gp_Pnt& thePnt, bool IsToLocalCS ) const; public: @@ -214,6 +216,7 @@ private: private: Handle(TDocStd_Document) myDoc; ///< OCAF document instance corresponding for keeping all persistent data int myTransactionsAfterSave; ///< number of transactions after the last "save" call, used for "IsModified" method + double myLX, myLY; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index aaa13984..4aef231e 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -1501,21 +1501,31 @@ void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList ) void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* ) { - double aX, aY, aZ; + double X, Y, Z; bool doShow = false; HYDROGUI_Displayer* aDisplayer = getDisplayer(); if ( aDisplayer ) aDisplayer->SaveCursorViewPosition( theViewWindow ); - doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, aX, aY, aZ ); + doShow = aDisplayer->GetCursorViewCoordinates( theViewWindow, X, Y, Z ); if ( doShow ) { // Show the coordinates in the status bar SUIT_Desktop* aDesktop = getApp()->desktop(); - if ( aDesktop && aDesktop->statusBar() ) { - QString aXStr = HYDROGUI_Tool::GetCoordinateString( aX ); - QString anYStr = HYDROGUI_Tool::GetCoordinateString( aY ); - aDesktop->statusBar()->showMessage( tr("COORDINATES_INFO").arg( aXStr ).arg( anYStr ) ); + if ( aDesktop && aDesktop->statusBar() ) + { + gp_Pnt aWPnt( X, Y, Z ); + int aStudyId = application()->activeStudy()->id(); + HYDROData_Document::Document( aStudyId )->Transform( aWPnt, false ); + double WX = aWPnt.X(), WY = aWPnt.Y(); + + QString aXStr = HYDROGUI_Tool::GetCoordinateString( X ); + QString anYStr = HYDROGUI_Tool::GetCoordinateString( Y ); + QString aWXStr = HYDROGUI_Tool::GetCoordinateString( WX ); + QString aWYStr = HYDROGUI_Tool::GetCoordinateString( WY ); + QString aMsg = tr( "COORDINATES_INFO" ); + aMsg = aMsg.arg( aXStr ).arg( anYStr ).arg( aWXStr ).arg( aWYStr ); + aDesktop->statusBar()->showMessage( aMsg ); } } } diff --git a/src/HYDROGUI/HYDROGUI_Shape.cxx b/src/HYDROGUI/HYDROGUI_Shape.cxx index d855380c..550deb93 100644 --- a/src/HYDROGUI/HYDROGUI_Shape.cxx +++ b/src/HYDROGUI/HYDROGUI_Shape.cxx @@ -307,6 +307,12 @@ void HYDROGUI_Shape::update( const bool theIsUpdateViewer ) gp_Pnt aPnt3( aRect.bottomRight().x(), aRect.bottomRight().y(), 0 ); gp_Pnt aPnt4( aRect.bottomLeft().x(), aRect.bottomLeft().y(), 0 ); + Handle_HYDROData_Document aDoc = HYDROData_Document::Document( anImageObj->Label() ); + aDoc->Transform( aPnt1, true ); + aDoc->Transform( aPnt2, true ); + aDoc->Transform( aPnt3, true ); + aDoc->Transform( aPnt4, true ); + TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge( aPnt1, aPnt2 ).Edge(); TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge( aPnt2, aPnt3 ).Edge(); TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge( aPnt3, aPnt4 ).Edge(); diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 781e984b..2b0a8a31 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -195,7 +195,10 @@ All supported formats (*.brep *.iges *.igs *.step *.stp) COORDINATES_INFO - X: %1, Y: %2 + +X: %1, Y: %2 +WX: %3, WY: %4 + POLYLINE3D_POLYLINE -- 2.39.2