1313#include " AffineImage.h"
1414#include " GeoBase.h"
1515#include " MvtLayer.h"
16+ #include " ../XToolImage/XTiffWriter.h"
1617
1718// ==============================================================================
1819// ObjectViewerComponent : constructeur
@@ -71,6 +72,12 @@ ObjectViewerComponent::ObjectViewerComponent()
7172 addAndMakeVisible (m_sldFrameExport);
7273 m_sldFrameExport.addListener (this );
7374
75+ addAndMakeVisible (m_lblFrameSize);
76+
77+ m_btnExportUsefulFrame.setButtonText (juce::translate (" Export" ));
78+ addAndMakeVisible (m_btnExportUsefulFrame);
79+ m_btnExportUsefulFrame.addListener (this );
80+
7481 // Interface pour les objets vectoriels
7582 m_btnPen.setButtonText (juce::translate (" Pen" ));
7683 m_btnFill.setButtonText (juce::translate (" Fill" ));
@@ -131,6 +138,8 @@ void ObjectViewerComponent::resized()
131138 m_sldToneMappingPower.setBounds (10 , 220 , 100 , 40 );
132139 m_sldToneMappingSharpness.setBounds (120 , 220 , 100 , 40 );
133140 m_sldFrameExport.setBounds (10 , 270 , 100 , 40 );
141+ m_lblFrameSize.setBounds (120 , 275 , 100 , 30 );
142+ m_btnExportUsefulFrame.setBounds (65 , 320 , 100 , 30 );
134143
135144 // Interface pour les objets vectoriels
136145 m_btnPen.setBounds (10 , 10 , 100 , 30 );
@@ -191,6 +200,10 @@ void ObjectViewerComponent::buttonClicked(juce::Button* button)
191200{
192201 if (m_Object == nullptr )
193202 return ;
203+ if (button == &m_btnExportUsefulFrame) {
204+ ExportUsefulFrame ();
205+ return ;
206+ }
194207 XGeoVector* V = dynamic_cast <XGeoVector*>(m_Object);
195208 if (V != nullptr ) {
196209 if (button == &m_btnRestore) {
@@ -261,6 +274,8 @@ bool ObjectViewerComponent::SetSelection(XGeoObject* S)
261274 m_sldToneMappingPower.setVisible (false );
262275 m_sldToneMappingSharpness.setVisible (false );
263276 m_sldFrameExport.setVisible (false );
277+ m_btnExportUsefulFrame.setVisible (false );
278+ m_lblFrameSize.setVisible (false );
264279 m_btnPen.setVisible (false );
265280 m_btnFill.setVisible (false );
266281 m_sldPenWidth.setVisible (false );
@@ -311,6 +326,8 @@ bool ObjectViewerComponent::SetRotationImage(RotationImage* image)
311326 m_sldToneMappingPower.setVisible (true );
312327 m_sldToneMappingSharpness.setVisible (true );
313328 m_sldFrameExport.setVisible (true );
329+ m_btnExportUsefulFrame.setVisible (true );
330+ m_lblFrameSize.setVisible (true );
314331
315332 XPt2D S = image->Centroide ();
316333 m_sldXCenter.setRange (S.X - 200 ., S.X + 200 ., 5 .);
@@ -405,35 +422,74 @@ bool ObjectViewerComponent::UpdateInternetImage(GeoInternetImage* internet)
405422}
406423
407424// ==============================================================================
408- // UpdateFrameExport : mise a jour du cadre pour l'export
425+ // ComputeFrameExport : calcul du cadre pour l'export
409426// ==============================================================================
410- bool ObjectViewerComponent::UpdateFrameExport (RotationImage* image)
427+ void ObjectViewerComponent::ComputeFrameExport (RotationImage* image, std::vector<XPt2D>& T )
411428{
412429 XPt3D C = m_Target;
413- double rot = image->Rotation ();
430+ double rot = image->Rotation (); rot = 0 .;
414431 double ratio = m_sldFrameExport.getValue () * 0.005 ;
415432 double W = image->GetImageW (), H = image->GetImageH ();
433+ W = H = XMin (W, H);
416434 double gsd = image->Resolution ();
417- juce::String message = " UpdateTargetPoly: " ;
418- std::vector<XPt3D> T ;
435+
436+ T. clear () ;
419437 double X = ratio * W * gsd * cos (rot) - ratio * H * gsd * sin (rot);
420438 double Y = ratio * W * gsd * sin (rot) + ratio * H * gsd * cos (rot);
421- T.push_back (XPt3D (C.X + X, C.Y + Y, 0 .));
422- message += (juce::String (C.X + X, 2 ) + " :" + juce::String (C.Y + Y, 2 ) + " :0.0:" );
439+ T.push_back (XPt2D (C.X + X, C.Y + Y));
423440 X = ratio * W * gsd * cos (rot) + ratio * H * gsd * sin (rot);
424441 Y = ratio * W * gsd * sin (rot) - ratio * H * gsd * cos (rot);
425- T.push_back (XPt3D (C.X + X, C.Y + Y, 0 .));
426- message += (juce::String (C.X + X, 2 ) + " :" + juce::String (C.Y + Y, 2 ) + " :0.0:" );
442+ T.push_back (XPt2D (C.X + X, C.Y + Y));
427443 X = -ratio * W * gsd * cos (rot) + ratio * H * gsd * sin (rot);
428444 Y = -ratio * W * gsd * sin (rot) - ratio * H * gsd * cos (rot);
429- T.push_back (XPt3D (C.X + X, C.Y + Y, 0 .));
430- message += (juce::String (C.X + X, 2 ) + " :" + juce::String (C.Y + Y, 2 ) + " :0.0:" );
445+ T.push_back (XPt2D (C.X + X, C.Y + Y));
431446 X = -ratio * W * gsd * cos (rot) - ratio * H * gsd * sin (rot);
432447 Y = -ratio * W * gsd * sin (rot) + ratio * H * gsd * cos (rot);
433- T.push_back (XPt3D (C.X + X, C.Y + Y, 0 . ));
434- message += ( juce::String (C. X + X, 2 ) + " : " + juce::String (C. Y + Y, 2 ) + " :0.0 " );
448+ T.push_back (XPt2D (C.X + X, C.Y + Y));
449+ }
435450
451+ // ==============================================================================
452+ // UpdateFrameExport : mise a jour du cadre pour l'export
453+ // ==============================================================================
454+ bool ObjectViewerComponent::UpdateFrameExport (RotationImage* image)
455+ {
456+ juce::String message = " UpdateTargetPoly:" ;
457+ std::vector<XPt2D> T;
458+ ComputeFrameExport (image, T);
459+ message += (juce::String (T[0 ].X , 2 ) + " :" + juce::String (T[0 ].Y , 2 ) + " :0.0:" );
460+ message += (juce::String (T[1 ].X , 2 ) + " :" + juce::String (T[1 ].Y , 2 ) + " :0.0:" );
461+ message += (juce::String (T[2 ].X , 2 ) + " :" + juce::String (T[2 ].Y , 2 ) + " :0.0:" );
462+ message += (juce::String (T[3 ].X , 2 ) + " :" + juce::String (T[3 ].Y , 2 ) + " :0.0" );
436463 sendActionMessage (message);
437-
464+ double gsd = image->Resolution ();
465+ m_lblFrameSize.setText (juce::String (XRint (fabs (T[2 ].X - T[0 ].X )/gsd)) + " ;" + juce::String (XRint (fabs (T[1 ].Y - T[0 ].Y )/gsd)),
466+ juce::NotificationType::dontSendNotification);
438467 return true ;
468+ }
469+
470+ // ==============================================================================
471+ // ExportUsefulFrame : export du cadre pour l'export
472+ // ==============================================================================
473+ void ObjectViewerComponent::ExportUsefulFrame ()
474+ {
475+ RotationImage* image = dynamic_cast <RotationImage*>(m_Object);
476+ if (image == nullptr )
477+ return ;
478+ std::vector<XPt2D> T;
479+ ComputeFrameExport (image, T);
480+ XFrame F;
481+ for (size_t i = 0 ; i < T.size (); i++)
482+ F += T[i];
483+ juce::String filename = AppUtil::SaveFile (" ExportUsefulFrame" , juce::translate (" File to save" ), " *.png" );
484+ if (filename.isEmpty ())
485+ return ;
486+ juce::MouseCursor::showWaitCursor ();
487+ juce::Image export_ima = image->GetAreaImage (F, image->Resolution ());
488+ juce::File file (filename);
489+ if (file.existsAsFile ())
490+ file.deleteFile ();
491+ juce::FileOutputStream outputFileStream (file);
492+ juce::PNGImageFormat png;
493+ png.writeImageToStream (export_ima, outputFileStream);
494+ juce::MouseCursor::hideWaitCursor ();
439495}
0 commit comments