Skip to content

Commit 96f0ce4

Browse files
committed
Export image
1 parent 9d1781f commit 96f0ce4

12 files changed

Lines changed: 129 additions & 139 deletions

File tree

IGNMap/Source/GeoBase.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,11 +759,13 @@ void GeoTools::ColorizeClasses(XGeoBase* base)
759759
// Enregistrement d'un objet dans une map et une classe
760760
//-----------------------------------------------------------------------------
761761
bool GeoTools::RegisterObject(XGeoBase* base, XGeoVector* V, std::string mapName, std::string layerName, std::string className,
762-
int transparency, uint32_t color, uint32_t fill, uint32_t zorder, uint8_t size)
762+
bool selectable, uint32_t zorder,
763+
int transparency, uint32_t color, uint32_t fill, uint8_t size)
763764
{
764765
XGeoClass* raster_class = base->AddClass(layerName.c_str(), className.c_str());
765766
if (raster_class == nullptr)
766767
return false;
768+
raster_class->Selectable(selectable);
767769
raster_class->Repres()->Transparency((uint8_t)transparency);
768770
raster_class->Repres()->Color(color);
769771
raster_class->Repres()->FillColor(fill);

IGNMap/Source/GeoBase.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ namespace GeoTools {
172172
//==============================================================================
173173
namespace GeoTools {
174174
bool RegisterObject(XGeoBase* base, XGeoVector* V, std::string mapName, std::string layerName, std::string className,
175-
int transparency = 0, uint32_t color = 0xFFFFFFFF, uint32_t fill = 0xFFFFFFFF, uint32_t zorder = 0, uint8_t size = 1);
175+
bool selectable = true, uint32_t zorder = 10,
176+
int transparency = 0, uint32_t color = 0xFFFFFFFF, uint32_t fill = 0xFFFFFFFF, uint8_t size = 1);
176177
void ColorizeClasses(XGeoBase* base);
177178
juce::File CreateCacheDir(juce::String name);
178179
void UpdateProjection(XGeoBase* base);

IGNMap/Source/MainComponent.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,8 @@ bool MainComponent::perform(const InvocationInfo& info)
581581
//AddWmtsServer("data.geopf.fr/wmts", "ORTHOIMAGERY.ORTHOPHOTOS.ORTHO-EXPRESS.2024", "PM_0_19", "jpeg", 256, 256, 19);
582582
break;
583583
case CommandIDs::menuAddGeoportailCartes:
584-
AddWmtsServer("data.geopf.fr/private/wmts", "GEOGRAPHICALGRIDSYSTEMS.MAPS.SCAN25TOUR", "PM", "jpeg", 256, 256, 16, "ign_scan_ws");
584+
//AddWmtsServer("data.geopf.fr/private/wmts", "GEOGRAPHICALGRIDSYSTEMS.MAPS.SCAN25TOUR", "PM", "jpeg", 256, 256, 16, "ign_scan_ws");
585+
AddWmtsServer("data.geopf.fr/private/wmts", "GEOGRAPHICALGRIDSYSTEMS.MAPS", "PM", "jpeg", 256, 256, 16, "ign_scan_ws");
585586
break;
586587
case CommandIDs::menuAddGeoportailPlanIGN:
587588
AddWmtsServer("data.geopf.fr/wmts", "GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2", "PM_0_19", "png", 256, 256, 19);
@@ -1303,7 +1304,7 @@ bool MainComponent::AddOSMServer()
13031304

13041305
OsmLayer* osm = new OsmLayer("tile.openstreetmap.org");
13051306
osm->SetFrame(F);
1306-
if (!GeoTools::RegisterObject(&m_GeoBase, osm, "OSM", "OSM", "tile.openstreetmap.org")) {
1307+
if (!GeoTools::RegisterObject(&m_GeoBase, osm, "OSM", "OSM", "tile.openstreetmap.org", false, 0)) {
13071308
delete osm;
13081309
return false;
13091310
}
@@ -1336,7 +1337,7 @@ bool MainComponent::AddWmtsServer(std::string server, std::string layer, std::st
13361337

13371338
WmtsLayerWebMerc* wmts = new WmtsLayerWebMerc(server, layer, TMS, format, tileW, tileH, max_zoom, apikey);
13381339
wmts->SetFrame(F);
1339-
if (!GeoTools::RegisterObject(&m_GeoBase, wmts, "WMTS", "WMTS", layer)) {
1340+
if (!GeoTools::RegisterObject(&m_GeoBase, wmts, "WMTS", "WMTS", layer, false, 0)) {
13401341
delete wmts;
13411342
return false;
13421343
}
@@ -1369,7 +1370,7 @@ bool MainComponent::AddMvtServer(std::string url, std::string ext, std::string s
13691370
MvtLayer* mvt = new MvtLayer(url, ext, tileW, tileH, max_zoom);
13701371
mvt->SetFrame(F);
13711372
mvt->LoadStyle(style);
1372-
if (!GeoTools::RegisterObject(&m_GeoBase, mvt, "MVT", "MVT", url)) {
1373+
if (!GeoTools::RegisterObject(&m_GeoBase, mvt, "MVT", "MVT", url, false, 0)) {
13731374
delete mvt;
13741375
return false;
13751376
}
@@ -1996,23 +1997,27 @@ void MainComponent::SetDefaultLayers(juce::String layers)
19961997
{
19971998
if (layers.isEmpty())
19981999
return;
1999-
m_MapView.get()->setMouseCursor(juce::MouseCursor(juce::MouseCursor::WaitCursor));
2000+
juce::MouseCursor::showWaitCursor();
20002001
m_GeoBase.ClearSelection();
20012002
actionListenerCallback("UpdateSelectFeatures");
20022003
if (layers == "Empty") {
20032004
m_GeoBase.RemoveClass("MVT", "https://data.geopf.fr/tms/1.0.0/PLAN.IGN");
2005+
m_GeoBase.RemoveClass("WMTS", "GEOGRAPHICALGRIDSYSTEMS.MAPS");
20042006
m_GeoBase.RemoveClass("WMTS", "ORTHOIMAGERY.ORTHOPHOTOS");
20052007
m_ImageViewer.get()->SetBase(&m_GeoBase);
20062008
actionListenerCallback("UpdateRaster");
20072009
}
20082010
if (layers == "Ortho") {
20092011
m_GeoBase.RemoveClass("MVT", "https://data.geopf.fr/tms/1.0.0/PLAN.IGN");
2012+
m_GeoBase.RemoveClass("WMTS", "GEOGRAPHICALGRIDSYSTEMS.MAPS");
20102013
AddWmtsServer("data.geopf.fr/wmts", "ORTHOIMAGERY.ORTHOPHOTOS", "PM_0_19", "jpeg", 256, 256, 20);
20112014
}
20122015
if (layers == "Carto") {
20132016
m_GeoBase.RemoveClass("WMTS", "ORTHOIMAGERY.ORTHOPHOTOS");
2014-
AddMvtServer("https://data.geopf.fr/tms/1.0.0/PLAN.IGN", "pbf",
2015-
"https://data.geopf.fr/annexes/ressources/vectorTiles/styles/PLAN.IGN/standard.json", 256, 256, 18);
2017+
m_GeoBase.RemoveClass("MVT", "https://data.geopf.fr/tms/1.0.0/PLAN.IGN");
2018+
AddWmtsServer("data.geopf.fr/private/wmts", "GEOGRAPHICALGRIDSYSTEMS.MAPS", "PM", "jpeg", 256, 256, 16, "ign_scan_ws");
2019+
//AddMvtServer("https://data.geopf.fr/tms/1.0.0/PLAN.IGN", "pbf",
2020+
// "https://data.geopf.fr/annexes/ressources/vectorTiles/styles/PLAN.IGN/standard.json", 256, 256, 18);
20162021
}
20172022
if (layers == "Ortho+Carto") {
20182023
AddWmtsServer("data.geopf.fr/wmts", "ORTHOIMAGERY.ORTHOPHOTOS", "PM_0_19", "jpeg", 256, 256, 20);
@@ -2021,10 +2026,9 @@ void MainComponent::SetDefaultLayers(juce::String layers)
20212026
"https://data.geopf.fr/annexes/ressources/vectorTiles/styles/PLAN.IGN/toponymes.json", 256, 256, 18);
20222027
}
20232028

2024-
m_MapView.get()->setMouseCursor(juce::MouseCursor(juce::MouseCursor::NormalCursor));
2029+
juce::MouseCursor::hideWaitCursor();
20252030
}
20262031

2027-
20282032
//==============================================================================
20292033
// Ouverture d'une fenetre outil
20302034
//==============================================================================

IGNMap/Source/ObjectViewer.cpp

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
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
}

IGNMap/Source/ObjectViewer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ class ObjectViewerComponent : public juce::Component, public juce::ActionListene
3939
bool SetSelection(XGeoObject*);
4040
bool SetRotationImage(RotationImage* image);
4141
bool UpdateRotationImage(RotationImage* image);
42+
void ComputeFrameExport(RotationImage* image, std::vector<XPt2D>& T);
4243
bool UpdateFrameExport(RotationImage* image);
44+
void ExportUsefulFrame();
4345
bool SetGeoRepres(XGeoRepres* R);
4446
bool SetInternetImage(GeoInternetImage* internet);
4547
bool UpdateInternetImage(GeoInternetImage* internet);
@@ -59,6 +61,8 @@ class ObjectViewerComponent : public juce::Component, public juce::ActionListene
5961
juce::Slider m_sldToneMappingPower;
6062
juce::Slider m_sldToneMappingSharpness;
6163
juce::Slider m_sldFrameExport;
64+
juce::TextButton m_btnExportUsefulFrame;
65+
juce::Label m_lblFrameSize;
6266

6367
// Interface pour les objets vectoriels
6468
ColourChangeButton m_btnPen;

IGNMap/Source/WmtsTmsViewer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ void WmtsViewerComponent::actionListenerCallback(const juce::String& message)
225225
WmtsLayerTMS* layer = new WmtsLayerTMS(m_strLastUrl.toStdString());
226226
if (m_Capabilities.SetLayerTMS(layer, m_Model.m_Proxy[index].Id, m_Model.m_Proxy[index].TMS)) {
227227
if (layer->FindProjection()) {
228-
if (GeoTools::RegisterObject(m_Base, layer, "WMTS", "WMTS", layer->Name())) {
228+
if (GeoTools::RegisterObject(m_Base, layer, "WMTS", "WMTS", layer->Name(), false, 0)) {
229229
sendActionMessage("AddWmtsLayer");
230230
m_Table.repaint();
231231
return;
@@ -489,7 +489,7 @@ void TmsViewerComponent::actionListenerCallback(const juce::String& message)
489489
if ((m_Model.m_Proxy[index].Format == "pbf")|| (m_Model.m_Proxy[index].Format == "mvt")) {
490490
MvtLayer* mvt = new MvtLayer();
491491
if (mvt->ReadServer(m_Model.m_Proxy[index].Href)) {
492-
if (GeoTools::RegisterObject(m_Base, mvt, "MVT", "MVT", m_Model.m_Proxy[index].Id.toStdString())) {
492+
if (GeoTools::RegisterObject(m_Base, mvt, "MVT", "MVT", m_Model.m_Proxy[index].Id.toStdString(), false, 0)) {
493493
sendActionMessage("AddWmtsLayer");
494494
m_Table.repaint();
495495
return;
@@ -500,7 +500,7 @@ void TmsViewerComponent::actionListenerCallback(const juce::String& message)
500500
else {
501501
TmsLayer* layer = new TmsLayer();
502502
if (layer->ReadServer(m_Model.m_Proxy[index].Href)) {
503-
if (GeoTools::RegisterObject(m_Base, layer, "TMS", "TMS", m_Model.m_Proxy[index].Id.toStdString())) {
503+
if (GeoTools::RegisterObject(m_Base, layer, "TMS", "TMS", m_Model.m_Proxy[index].Id.toStdString(), false, 0)) {
504504
sendActionMessage("AddWmtsLayer");
505505
m_Table.repaint();
506506
return;

0 commit comments

Comments
 (0)