// FuncLoadSaveFichierJSON.inc //****************************************************************************** function TToporobotStructure2012.LoadFromJSON(const FichierJSON: TStringDirectoryFilename): integer; var EPSGDefault : TLabelSystemesCoordsEPSG; JSONRoot : TJsonNode; NodeGeneral : TJsonNode; NodeEntrances : TJsonNode; NodeReseaux : TJsonNode; NodeSecteurs : TJsonNode; NodeCodes : TJsonNode; NodeExpes : TJsonNode; NodeSeries : TJsonNode; NodeSplays : TJsonNode; NodeCode , NodeExpe: TJsonNode; NodeSplay : TJsonNode; NodeEntrance, NodeReseau, NodeSecteur: TJsonNode; MyCode : TCode; MyExpe : TExpe; MySerie : TObjSerie; i: Integer; QErrMsg: string; YYYY, MM, DD: word; MySplay: TViseeAntenne; MyEntrance: TEntrance; PosEntrance: TPoint3Df; MyReseau: TReseau; MySecteur: TSecteur; function CheckJSON(out ErrMsg: string): boolean; const FMT_ERR_SECTION_NOT_FOUND = 'Section %s not found, '; begin ErrMsg := 'Void JSON'; result := false; if (JSONRoot.Count = 0) then exit; ErrMsg := ''; AfficherMessageErreur('-- Check mandatory sections'); // sections obligatoires: Codes, Expés et Séries NodeCodes := JSONRoot.Child(JSON_NODE_SECTION_CODES); if (NodeCodes = nil) then ErrMsg += Format(FMT_ERR_SECTION_NOT_FOUND, [JSON_NODE_SECTION_CODES]); NodeExpes := JSONRoot.Child(JSON_NODE_SECTION_EXPES); if (NodeExpes = nil) then ErrMsg += Format(FMT_ERR_SECTION_NOT_FOUND, [JSON_NODE_SECTION_EXPES]); NodeSeries := JSONRoot.Child(JSON_NODE_SECTION_SERIES); if (NodeSeries = nil) then ErrMsg += Format(FMT_ERR_SECTION_NOT_FOUND, [JSON_NODE_SECTION_SERIES]); Result := ('' = ErrMsg); if (not Result) then begin AfficherMessageErreur('*** Missing mandatory sections: ' + ErrMsg); exit; end; Result := false; AfficherMessageErreur('-- Check header'); ErrMsg := ''; // section obligatoire reconstructible NodeGeneral := JSONRoot.Child(JSON_NODE_SECTION_GENERAL); if (NodeGeneral = nil) then ErrMsg += Format(FMT_ERR_SECTION_NOT_FOUND, [JSON_NODE_SECTION_GENERAL]); AfficherMessageErreur('-- Check optional sections'); ErrMsg := ''; // sections facultatives: Entrées, Réseaux, Secteurs et Splays NodeEntrances := JSONRoot.Child(JSON_NODE_SECTION_ENTRANCES); if (NodeEntrances = nil) then ErrMsg += Format(FMT_ERR_SECTION_NOT_FOUND, [JSON_NODE_SECTION_ENTRANCES]); NodeReseaux := JSONRoot.Child(JSON_NODE_SECTION_RESEAUX); if (NodeReseaux = nil) then ErrMsg += Format(FMT_ERR_SECTION_NOT_FOUND, [JSON_NODE_SECTION_RESEAUX]); NodeSecteurs := JSONRoot.Child(JSON_NODE_SECTION_SECTEURS); if (NodeSecteurs = nil) then ErrMsg += Format(FMT_ERR_SECTION_NOT_FOUND, [JSON_NODE_SECTION_SECTEURS]); NodeSplays := JSONRoot.Child(JSON_NODE_SECTION_SPLAYS); if (NodeSplays = nil) then ErrMsg += Format(FMT_ERR_SECTION_NOT_FOUND, [JSON_NODE_SECTION_SPLAYS]); AfficherMessageErreur('*** Missing optional sections: ' + ErrMsg); Result := True; end; function CreateSerie(const ND: TJsonNode; out SR: TObjSerie): boolean; var LesVisees, NodeVisee: TJsonNode; NbV, s: Integer; begin Result := false; SR := TObjSerie.Create; try SR.ClearStations(); SR.SetNumeroSerie(TNumeroSerie(ND.Child(JSON_ATTR_SERIE_Numero).AsInteger)); SR.SetNomObsSerie(ND.Child(JSON_ATTR_SERIE_NAME).AsString, ND.Child(JSON_ATTR_SERIE_OBS).AsString); SR.SetNumeroEntrance(ND.Child(JSON_ATTR_SERIE_ENTRANCE).AsInteger); SR.SetNumeroReseau(ND.Child(JSON_ATTR_SERIE_RESEAU).AsInteger); SR.SetSeriePtExtremites(ND.Child(JSON_ATTR_SERIE_SERDEP).AsInteger, ND.Child(JSON_ATTR_SERIE_PTDEP).AsInteger, ND.Child(JSON_ATTR_SERIE_SERARR).AsInteger, ND.Child(JSON_ATTR_SERIE_PTARR).AsInteger); SR.SetRaideur(ND.Child(JSON_ATTR_SERIE_RAIDEUR).AsNumber); LesVisees := ND.Child(JSON_NODE_STATIONS); NbV := LesVisees.Count; for s := 0 to nbV - 1 do begin NodeVisee := LesVisees.Child(s); SR.AddVisee(NodeVisee.Child(JSON_ATTR_VISEE_SECTEUR).AsInteger, NodeVisee.Child(JSON_ATTR_VISEE_CODE).AsInteger, NodeVisee.Child(JSON_ATTR_VISEE_EXPE).AsInteger, TTypeDeVisee(NodeVisee.Child(JSON_ATTR_VISEE_TYPE).AsInteger), NodeVisee.Child(JSON_ATTR_VISEE_LONG).AsNumber, NodeVisee.Child(JSON_ATTR_VISEE_AZ).AsNumber, NodeVisee.Child(JSON_ATTR_VISEE_P).AsNumber, NodeVisee.Child(JSON_ATTR_VISEE_LG).AsNumber, NodeVisee.Child(JSON_ATTR_VISEE_LD).AsNumber, NodeVisee.Child(JSON_ATTR_VISEE_HZ).AsNumber, NodeVisee.Child(JSON_ATTR_VISEE_HN).AsNumber, NodeVisee.Child(JSON_ATTR_VISEE_LBL).AsString, NodeVisee.Child(JSON_ATTR_VISEE_OBS).AsString, Now(), 0.00, 0.00); end; except end; end; begin Result := -1; AfficherMemoryUsage(); AfficherMsgClass(self, 'LoadFromJSON(): %s', [FichierJSON]); AfficherMsgErrClass(self, 'LoadFromJSON(): %s', [FichierJSON]); SetNomEtude('Etude001'); // nom étude par défaut SetCommentairesEtude('Issued from JSON format'); EPSGDefault.CodeEPSG := DEFAULT_SYSTEME_COORDONNEES_CODE_EPSG; EPSGDefault.NomEPSG := DEFAULT_SYSTEME_COORDONNEES_NOM; SetCodeEPSGSystemeCoordonnees(EPSGDefault); // réinit du document self.ReInitialiser(True); //*) AfficherMessageErreur('-- Chargement du JSON'); JSONRoot := TJsonNode.Create; try try JSONRoot.LoadFromFile(FichierJSON); AfficherMessageErreur('-- Chargement du JSON: %d sections', [JSONRoot.Count]); if (not CheckJSON(QErrMsg)) then exit(-1); // Les entrées if (self.GetNbEntrances() = 0) then begin if ((NodeEntrances = nil) OR (NodeEntrances.Count = 0)) then begin AfficherMessageErreur('Pas de section Entrance - Reconstruction'); MyEntrance.setFrom('Main Entrance', '', self.PositionDuPointZero, 1, 0, clRed, 'Regenerated', True, tteGROTTE); self.AddEntrance(MyEntrance); end else begin for i := 0 to NodeEntrances.Count - 1 do begin NodeEntrance := NodeEntrances.Child(i); PosEntrance.setFrom(NodeEntrance.Child(JSON_ATTR_ENTRANCE_X).AsNumber, NodeEntrance.Child(JSON_ATTR_ENTRANCE_Y).AsNumber, NodeEntrance.Child(JSON_ATTR_ENTRANCE_Z).AsNumber); MyEntrance.setFrom(NodeEntrance.Child(JSON_ATTR_ENTRANCE_NAME).AsString, NodeEntrance.Child(JSON_ATTR_ENTRANCE_IDTERRAIN).AsString, PosEntrance, NodeEntrance.Child(JSON_ATTR_ENTRANCE_REFSERIE).AsInteger, NodeEntrance.Child(JSON_ATTR_ENTRANCE_REFPT).AsInteger, clRed, NodeEntrance.Child(JSON_ATTR_ENTRANCE_OBS).AsString, True, TTypeOfEntrance( NodeEntrance.Child(JSON_ATTR_ENTRANCE_TYPE).AsInteger)); self.AddEntrance(MyEntrance); end; // for i := 0 to NodeEntrances.Count - 1 do // On récupère l'entrée 0 pour renseigner la section General MyEntrance := Self.GetEntrance(0); self.SetRefSeriePoint(MyEntrance.eRefSer, MyEntrance.eRefSt); self.SetDefaultCoords(MyEntrance.ePosition); end; end; // Les réseaux if ((NodeReseaux = nil) OR (NodeReseaux.Count = 0)) then begin AfficherMessageErreur('Pas de section Reseaux - Reconstruction'); MyReseau.setFrom(clRed, 0, GetResourceString(rsMAIN_NETWORK), ''); self.AddReseau(MyReseau); end else begin FTableReseaux.ClearListe(); for i := 0 to NodeReseaux.Count - 1 do begin NodeReseau := NodeReseaux.Child(i); MyReseau.setFrom(ColorHTMLToColor(NodeReseau.Child(JSON_ATTR_RESEAU_COLOR).AsString), NodeReseau.Child(JSON_ATTR_RESEAU_TYPE).AsInteger, NodeReseau.Child(JSON_ATTR_RESEAU_NAME).AsString, NodeReseau.Child(JSON_ATTR_RESEAU_OBS).AsString); self.AddReseau(MyReseau); end; // for i := 0 to NodeReseaux.Count - 1 do end; // Les secteurs if ((NodeSecteurs = nil) OR (NodeSecteurs.Count = 0)) then begin AfficherMessageErreur('Pas de section Secteurs - Reconstruction'); MySecteur.setFrom(clRed, GetResourceString(rsFIRST_SECTEUR)); self.AddSecteur(MySecteur); end else begin FTableSecteurs.ClearListe(); for i := 0 to NodeSecteurs.Count - 1 do begin NodeSecteur := NodeSecteurs.Child(i); MySecteur.setFrom(ColorHTMLToColor(NodeSecteur.Child(JSON_ATTR_SECTEUR_COLOR).AsString), NodeSecteur.Child(JSON_ATTR_SECTEUR_NAME).AsString); self.AddSecteur(MySecteur); end; // for i := 0 to NodeSecteurs.Count - 1 do end; // Les codes for i := 0 to NodeCodes.Count - 1 do begin NodeCode := NodeCodes.Child(i); MyCode.setUsualParameters(TNumeroCode(NodeCode.Child(JSON_ATTR_CODE_NUMERO).AsInteger), NodeCode.Child(JSON_ATTR_CODE_UCOMPASS).AsNumber, NodeCode.Child(JSON_ATTR_CODE_UCLINO).AsNumber, NodeCode.Child(JSON_ATTR_CODE_FACT_LONG).AsNumber, NodeCode.Child(JSON_ATTR_CODE_PSI_L).AsNumber, NodeCode.Child(JSON_ATTR_CODE_PSI_A).AsNumber, NodeCode.Child(JSON_ATTR_CODE_PSI_P).AsNumber, NodeCode.Child(JSON_ATTR_CODE_DIAM_BOULE1).AsNumber, NodeCode.Child(JSON_ATTR_CODE_DIAM_BOULE2).AsNumber, NodeCode.Child(JSON_ATTR_CODE_ERROR_TOURILLON).AsNumber, NodeCode.Child(JSON_ATTR_CODE_OBS).AsString); self.AddCode(MyCode); end; // Les expés AfficherMessageErreur('--- Liste des %d seances', [NodeCodes.Count]); for i := 0 to NodeExpes.Count - 1 do begin NodeExpe := NodeExpes.Child(i); DecodeDate(DateSQLToDatePascal(NodeExpe.Child(JSON_ATTR_EXPE_DATE).AsString), YYYY, MM, DD); MyExpe.setFrom(TNumeroExpe(NodeExpe.Child(JSON_ATTR_CODE_NUMERO).AsInteger), YYYY, MM, DD, NodeExpe.Child(JSON_ATTR_EXPE_IDXCOLOR).AsInteger, TModeCalculDeclimag(NodeExpe.Child(JSON_ATTR_EXPE_MODEDECL).AsInteger), NodeExpe.Child(JSON_ATTR_EXPE_DECLINAT).AsNumber, NodeExpe.Child(JSON_ATTR_EXPE_SURVEY1).AsString, NodeExpe.Child(JSON_ATTR_EXPE_SURVEY2).AsString, NodeExpe.Child(JSON_ATTR_EXPE_OBS).AsString); self.AddExpe(MyExpe); end; // Les séries AfficherMessageErreur('--- Liste des %d séries', [NodeSeries.Count]); for i := 0 to NodeSeries.Count - 1 do begin CreateSerie(NodeSeries.Child(i), MySerie); // CreateSerie() ajoute les visées AfficherMessageErreur(' Série %d = %d - %d.%d to %d.%d - %d shots - %s', [i, MySerie.NumeroDeSerie, MySerie.NoSerieDep, MySerie.NoPointDep, MySerie.NoSerieArr, MySerie.NoPointArr, MySerie.NbVisees, MySerie.NomSerie]); self.AddSerie(MySerie); // contrôle liste des visées de la série (* for j := 0 to MySerie.NbVisees - 1 do begin MyVisee := MySerie.GetVisee(j); AfficherMessageErreur(' --- ' + MyVisee.DebugString()); end; AfficherMessageErreur(''); //*) end; // Les splays AfficherMessageErreur('--- Liste des %d splays', [NodeSplays.Count]); if (NodeSplays.Count > 0) then begin for i := 0 to NodeSplays.Count - 1 do begin NodeSplay := NodeSplays.Child(i); MySplay.setFrom(NodeSplay.Child(JSON_ATTR_SPLAY_ENTRANCE).AsInteger, NodeSplay.Child(JSON_ATTR_SPLAY_NETWORK).AsInteger, NodeSplay.Child(JSON_ATTR_SPLAY_SECTEUR).AsInteger, NodeSplay.Child(JSON_ATTR_SPLAY_SERIE).AsInteger, NodeSplay.Child(JSON_ATTR_SPLAY_POINT).AsInteger, NodeSplay.Child(JSON_ATTR_SPLAY_LONG).AsNumber, NodeSplay.Child(JSON_ATTR_SPLAY_AZIMUT).AsNumber, NodeSplay.Child(JSON_ATTR_SPLAY_PENTE).AsNumber ); self.AddViseeAntenne(MySplay); end; // for i := 0 to NodeSplays.Count - 1 do end; // if (NodeSplays.Count > 0) then except pass; end; finally FreeAndNil(JSONRoot); end; //EXIT; // A virer dès mise au point //************************** Preconditionner(FichierJSON); //**************************** Result := self.GetNbSeries(); end; procedure TToporobotStructure2012.SaveToJSON(const FichierJSON: TStringDirectoryFilename); var i: Integer; JSONRoot: TJsonNode; NodeGeneral: TJsonNode; NodeListeEntrances: TJsonNode; NodeListeSeries: TJsonNode; NodeListeSplays: TJsonNode; NodeListeReseaux, NodeListeSecteurs: TJsonNode; NodeListeCodes, NodeListeExpes: TJsonNode; EPSG: TLabelSystemesCoordsEPSG; procedure WrtEntrance(const NodeParent: TJsonNode; const SP: TEntrance); var MyNode: TJsonNode; begin MyNode := NodeParent.Add(JSON_NODE_ENTRANCE); MyNode.AddInteger(JSON_ATTR_ENTRANCE_REFSERIE , SP.eRefSer); MyNode.AddInteger(JSON_ATTR_ENTRANCE_REFPT , SP.eRefSt); MyNode.AddString(JSON_ATTR_ENTRANCE_NAME , SP.eNomEntree); MyNode.AddString(JSON_ATTR_ENTRANCE_IDTERRAIN , SP.eIDTerrain); MyNode.AddFloat(JSON_ATTR_ENTRANCE_X, SP.ePosition.X); MyNode.AddFloat(JSON_ATTR_ENTRANCE_Y, SP.ePosition.Y); MyNode.AddFloat(JSON_ATTR_ENTRANCE_Z, SP.ePosition.Z); MyNode.AddColour(JSON_ATTR_ENTRANCE_COLOR , SP.eCouleur); MyNode.AddString(JSON_ATTR_ENTRANCE_OBS , SP.eObserv); MyNode.AddInteger(JSON_ATTR_ENTRANCE_TYPE, Ord(SP.eTypeEntrance)); end; procedure WrtReseau(const NodeParent: TJsonNode; const SP: TReseau); var MyNode: TJsonNode; begin MyNode := NodeParent.Add(JSON_NODE_RESEAU); MyNode.AddInteger(JSON_ATTR_RESEAU_TYPE , SP.TypeReseau); MyNode.AddString(JSON_ATTR_RESEAU_NAME , SP.NomReseau); MyNode.AddString(JSON_ATTR_RESEAU_OBS , SP.ObsReseau); MyNode.AddColour(JSON_ATTR_RESEAU_COLOR , SP.ColorReseau); end; procedure WrtSecteur(const NodeParent: TJsonNode; const SP: TSecteur); var MyNode: TJsonNode; begin MyNode := NodeParent.Add(JSON_NODE_SECTEUR); MyNode.AddColour(JSON_ATTR_SECTEUR_COLOR , SP.CouleurSecteur); MyNode.AddString(JSON_ATTR_SECTEUR_NAME , SP.NomSecteur); end; procedure WrtCode(const NodeParent: TJsonNode; const SP: TCode); var MyNode: TJsonNode; begin MyNode := NodeParent.Add(JSON_NODE_CODE); MyNode.AddInteger(JSON_ATTR_CODE_NUMERO , SP.IDCode); // Unités MyNode.AddFloat(JSON_ATTR_CODE_FACT_LONG , SP.FactLong); MyNode.AddFloat(JSON_ATTR_CODE_UCOMPASS , SP.GradAz); MyNode.AddFloat(JSON_ATTR_CODE_UCLINO , SP.GradInc); // Incertitudes MyNode.AddFloat(JSON_ATTR_CODE_PSI_L , SP.PsiL); MyNode.AddFloat(JSON_ATTR_CODE_PSI_A , SP.PsiAz); MyNode.AddFloat(JSON_ATTR_CODE_PSI_P , SP.PsiP); // Diamètre des boules de centrage / cibles MyNode.AddFloat(JSON_ATTR_CODE_ERROR_TOURILLON, SP.ErreurTourillonInM); MyNode.AddFloat(JSON_ATTR_CODE_DIAM_BOULE1 , SP.DiametreBoule1InM); MyNode.AddFloat(JSON_ATTR_CODE_DIAM_BOULE2 , SP.DiametreBoule2InM); // Angle limite MyNode.AddFloat(JSON_ATTR_CODE_ANGLIMITE , SP.AngLimite); // Fonctions de correction MyNode.AddFloat(JSON_ATTR_CODE_FUNC_CORR_AZ_CO , SP.ParamsFuncCorrAz.Co); MyNode.AddFloat(JSON_ATTR_CODE_FUNC_CORR_AZ_ERR_MAX , SP.ParamsFuncCorrAz.ErreurMax); MyNode.AddFloat(JSON_ATTR_CODE_FUNC_CORR_AZ_POS_ERR_MAX , SP.ParamsFuncCorrAz.PosErrMax); MyNode.AddFloat(JSON_ATTR_CODE_FUNC_CORR_INC_CO , SP.ParamsFuncCorrInc.Co); MyNode.AddFloat(JSON_ATTR_CODE_FUNC_CORR_INC_ERR_MAX , SP.ParamsFuncCorrInc.ErreurMax); MyNode.AddFloat(JSON_ATTR_CODE_FUNC_CORR_INC_POS_ERR_MAX , SP.ParamsFuncCorrInc.PosErrMax); // Commentaires MyNode.AddString(JSON_ATTR_CODE_OBS , SP.Commentaire); MyNode.AddString(JSON_ATTR_CODE_Description , SP.getLibelle()); end; procedure WrtExpe(const NodeParent: TJsonNode; const SP: TExpe); var MyNode: TJsonNode; begin MyNode := NodeParent.Add(JSON_NODE_EXPE); MyNode.AddInteger(JSON_ATTR_EXPE_NUMERO , SP.IDExpe); MyNode.AddInteger(JSON_ATTR_EXPE_IDXCOLOR , SP.IdxCouleur); MyNode.AddInteger(JSON_ATTR_EXPE_MODEDECL , Ord(SP.ModeDecl)); MyNode.AddDate(JSON_ATTR_EXPE_DATE , SP.DateExpe); MyNode.AddFloat(JSON_ATTR_EXPE_DECLINAT , SP.DeclinaisonInDegrees); // Commentaires MyNode.AddString(JSON_ATTR_EXPE_SURVEY1 , SP.Operateur); MyNode.AddString(JSON_ATTR_EXPE_SURVEY2 , SP.ClubSpeleo); MyNode.AddString(JSON_ATTR_EXPE_OBS , SP.Commentaire); MyNode.AddString(JSON_ATTR_EXPE_Description , SP.getLibelle()); end; procedure WrtSplay(const NodeParent: TJsonNode; const SP: TViseeAntenne); var MyNode: TJsonNode; begin MyNode := NodeParent.Add(JSON_NODE_SPLAY); MyNode.AddInteger(JSON_ATTR_SPLAY_NETWORK , SP.Reseau); MyNode.AddInteger(JSON_ATTR_SPLAY_ENTRANCE , 0); //SP.EntranceRatt); MyNode.AddInteger(JSON_ATTR_SPLAY_SECTEUR , SP.Secteur); MyNode.AddInteger(JSON_ATTR_SPLAY_SERIE , SP.SerieDepart); MyNode.AddInteger(JSON_ATTR_SPLAY_POINT , SP.PtDepart); MyNode.AddFloat(JSON_ATTR_SPLAY_LONG , SP.Longueur); MyNode.AddFloat(JSON_ATTR_SPLAY_AZIMUT , SP.Azimut); MyNode.AddFloat(JSON_ATTR_SPLAY_PENTE , SP.Pente); end; procedure WrtSerie(const NodeParent: TJsonNode; const OS: TObjSerie); var s, Nb: Integer; NodeSerie, NodeListeVisees, NodeVisee: TJsonNode; MyVisee: TUneVisee; begin NodeSerie := NodeParent.Add(JSON_NODE_SERIE); NodeSerie.AddInteger(JSON_ATTR_SERIE_Numero , OS.NumeroDeSerie); NodeSerie.AddString(JSON_ATTR_SERIE_NAME , OS.NomSerie); NodeSerie.AddString(JSON_ATTR_SERIE_OBS , OS.ObsSerie); NodeSerie.AddInteger(JSON_ATTR_SERIE_SERDEP , OS.NoSerieDep); NodeSerie.AddInteger(JSON_ATTR_SERIE_PTDEP , OS.NoPointDep); NodeSerie.AddInteger(JSON_ATTR_SERIE_SERARR , OS.NoSerieArr); NodeSerie.AddInteger(JSON_ATTR_SERIE_PTARR , OS.NoPointArr); NodeSerie.AddInteger(JSON_ATTR_SERIE_CHANCE , OS.Chance); NodeSerie.AddInteger(JSON_ATTR_SERIE_OBSTACLE , OS.GetObstacle()); NodeSerie.AddFloat(JSON_ATTR_SERIE_RAIDEUR , OS.Raideur); NodeSerie.AddInteger(JSON_ATTR_SERIE_ENTRANCE , OS.NumeroEntrance); NodeSerie.AddInteger(JSON_ATTR_SERIE_RESEAU , OS.NumeroReseau); NodeSerie.AddFloat(JSON_ATTR_SERIE_Gisement0 , OS.Gisement0); // les visées Nb := OS.NbVisees; NodeListeVisees := NodeSerie.add(JSON_NODE_STATIONS, TJsonNodeKind.nkArray); for s := 0 to Nb - 1 do begin MyVisee := OS.GetVisee(s); NodeVisee := NodeListeVisees.Add(JSON_NODE_VISEE); NodeVisee.AddString(JSON_ATTR_VISEE_LBL , MyVisee.IDTerrainStation); NodeVisee.AddInteger(JSON_ATTR_VISEE_SECTEUR , MyVisee.IDSecteur); NodeVisee.AddInteger(JSON_ATTR_VISEE_TYPE , Ord(MyVisee.TypeVisee)); NodeVisee.AddInteger(JSON_ATTR_VISEE_CODE , MyVisee.Code); NodeVisee.AddInteger(JSON_ATTR_VISEE_EXPE , MyVisee.Expe); NodeVisee.AddFloat(JSON_ATTR_VISEE_LONG , MyVisee.Longueur); NodeVisee.AddFloat(JSON_ATTR_VISEE_AZ , MyVisee.Azimut); NodeVisee.AddFloat(JSON_ATTR_VISEE_P , MyVisee.Pente); NodeVisee.AddFloat(JSON_ATTR_VISEE_LG , MyVisee.LG); NodeVisee.AddFloat(JSON_ATTR_VISEE_LD , MyVisee.LD); NodeVisee.AddFloat(JSON_ATTR_VISEE_HZ , MyVisee.HZ); NodeVisee.AddFloat(JSON_ATTR_VISEE_HN , MyVisee.HN); NodeVisee.AddFloat(JSON_ATTR_VISEE_LectureAR , MyVisee.LectureArriere); NodeVisee.AddFloat(JSON_ATTR_VISEE_LectureAV , MyVisee.LectureAvant); NodeVisee.AddString(JSON_ATTR_VISEE_OBS , MyVisee.Commentaires); end; end; begin AfficherMsgClass(self, 'SaveToJSON(): %s', [FichierJSON]); JSONRoot := TJsonNode.Create; try try JSONRoot.Clear; JSONRoot.Name := JSON_GHTOPO_ROOT; NodeGeneral := JSONRoot.Add(JSON_NODE_SECTION_GENERAL); EPSG := self.CodeEPSGSystemeCoordonnees; NodeGeneral.AddString(JSON_ATTR_NOM_ETUDE , self.NomEtude); NodeGeneral.AddString(JSON_ATTR_COMMENTAIRES_ETUDE , self.CommentairesEtude); NodeGeneral.AddInteger(JSON_ATTR_COORDS_SYSTEM_EPSG, EPSG.CodeEPSG); NodeGeneral.AddString(JSON_ATTR_COORDS_SYSTEM_NOM , EPSG.NomEPSG); NodeGeneral.AddDateTime(JSON_ATTR_HORODATE_CREATION, Now()); NodeListeEntrances := JSONRoot.Add(JSON_NODE_SECTION_ENTRANCES, TJsonNodeKind.nkArray); for i := 0 to GetNbEntrances() - 1 do WrtEntrance(NodeListeEntrances, GetEntrance(i)); NodeListeReseaux := JSONRoot.Add(JSON_NODE_SECTION_RESEAUX , TJsonNodeKind.nkArray); for i := 0 to GetNbReseaux() - 1 do WrtReseau(NodeListeReseaux, GetReseau(i)); NodeListeSecteurs := JSONRoot.Add(JSON_NODE_SECTION_SECTEURS , TJsonNodeKind.nkArray); for i := 0 to GetNbSecteurs() - 1 do WrtSecteur(NodeListeSecteurs, GetSecteur(i)); NodeListeCodes := JSONRoot.Add(JSON_NODE_SECTION_CODES , TJsonNodeKind.nkArray); for i := 1 to GetNbCodes() - 1 do WrtCode(NodeListeCodes, GetCode(i)); NodeListeExpes := JSONRoot.Add(JSON_NODE_SECTION_EXPES , TJsonNodeKind.nkArray); for i := 1 to GetNbExpes() - 1 do WrtExpe(NodeListeExpes, GetExpe(i)); NodeListeSeries := JSONRoot.Add(JSON_NODE_SECTION_SERIES , TJsonNodeKind.nkArray); for i := 1 to GetNbSeries() - 1 do WrtSerie(NodeListeSeries, GetSerie(i)); if (GetNbAntennes() > 0) then begin NodeListeSplays := JSONRoot.Add(JSON_NODE_SECTION_SPLAYS , TJsonNodeKind.nkArray); for i := 1 to GetNbAntennes() - 1 do WrtSplay(NodeListeSplays, GetViseeAntenne(i)); end; JSONRoot.SaveToFile(FichierJSON); except on E: exception do AfficherMessageErreur(E.Message); end; finally FreeAndNil(JSONRoot); end; end;