//{$INCLUDE DocDessinLoadFromFile.inc} // Include contenant la fonction de chargement du dessin // 25/08/2015: La procédure TDocumentDessin.LoadFromFile(const FichierGCD: string): boolean; // qui est volumineuse, est déportée dans le fichier d'inclusion // DocDessinLoadFromFile.inc // Ce fichier est une dépendance de unitdocdessin.pas function TDocumentDessin.LoadFromFile(const FichierGCD: TStringDirectoryFileName): boolean; type TStatusFindInclude = (tincNO_INCLUDE, tincOK_TO_READ, tincFILE_NOT_FOUND, tincANY_ERROR); var //DoCreateFirstSuperGroupe: Boolean; MySuperGroupe: TSuperGroupe; MyGroupe: TGroupeEntites; QFichierCorrect: Integer; MyDessinateur: TDessinateur; function HasInstructionInclude(const QInstructionInclude: string; const QLigne: string; const QNumeroLigne: integer; out IncludeFileName: TStringDirectoryFileName): TStatusFindInclude; var EWE: String; begin Result := tincNO_INCLUDE; try if (Pos(QInstructionInclude, QLigne) > 0) then begin EWE := QLigne; System.Delete(EWE, 1, length(QInstructionInclude)); //FFichierCenterlines := Trim(EWE); IncludeFileName := FDossierDuDocument + PathDelim + Trim(EWE); AfficherMessageErreur('*** Instruction %s trouvée en ligne %d - %s', [QInstructionInclude, QNumeroLigne, IncludeFileName]); AfficherMessageErreur('-- Lecture du fichier: ' + IncludeFileName); if (not FileExists(IncludeFileName)) then // test de l'existence du fichier begin AfficherMessageErreur('%s: "%s"', [rsERR_MSG_FILE_NOT_FOUND, IncludeFileName]); Result := tincFILE_NOT_FOUND; Exit; end; Result := tincOK_TO_READ; end; except Result := tincANY_ERROR; end; end; // Procédure récursive de lecture // Retourne 0 si aucune erreur // -1 si échec de lecture du fichier ppal // -2 si fichier INCLUDE introuvable // -3 si échec de lecture du fichier INCLUDE function LireUnFichier(const QFilename: string): integer; var fp : TextFile; MyLine : String; NumLigne: Int64; QFichierToInclude: TStringDirectoryFileName; Argv : TGHStringArrayExt; NbAc : Integer; i : Integer; SG : TSuperGroupe; G : TGroupeEntites; MyScrap : TScrap; CV : TCourbe; PLG : TPolygone; PLL : TPolyLigne; MyVertex : TVertexPolygon; MySimpleLigne : TSimpleLigne; MyTexte : TTextObject; MySymbole : TSymbole; MyIMG : TImageObject; IdxMaxGroupe: TIDGroupeEntites; LS: TStringList; QArc: TArcCourbe; SD: TDessinateur; function LireLigne(): string; begin ReadLn(fp, Result); Result := Trim(Result); // Ne pas remplacer les espaces par des tab: certains paramètres texte peuvent être impactés (* Result := StringReplace(Result, ' ', #9, [rfIgnoreCase, rfReplaceAll]); //*) Inc(NumLigne); if (NumLigne mod 10000 = 0) then AfficherMessage('Reading line %d', [NumLigne]); end; begin Result := -1; // lecture du fichier AfficherMessageErreur('--- 001'); NumLigne := 0; AssignFile(fp, QFilename); LS := TStringList.Create; AfficherMessageErreur('--- 002'); try ReSet(fp); while (not EOF(fp)) do begin MyLine := LireLigne(); if (MyLine = '') then Continue; if (Pos('#', MyLine) > 0) then Continue; // commentaires if (Pos(PREFIX_LINE_CODE_EPSG, MyLine) = 1) then // code EPSG; le mot-clé doit être impérativement en début de ligne begin Argv.SplitFrom(MyLine, #9); FCodeEPSG := Argv.getInt32(1, DEFAULT_SYSTEME_COORDONNEES_CODE_EPSG); /// StrToIntDef(Trim(Argv[1]), DEFAULT_SYSTEME_COORDONNEES_CODE_EPSG); end; // Nom de l'étude, réseau, commune, lieu-dit if (Pos(PREFIX_LINE_NOM_RESEAU_1, MyLine) = 1) then // type de réseau ou ligne 1 du nom du réseau begin Argv.SplitFrom(MyLine, #9); FNomReseau1 := Argv.getString(1); end; if (Pos(PREFIX_LINE_NOM_RESEAU_2, MyLine) = 1) then // Nom du réseau begin Argv.SplitFrom(MyLine, #9); FNomReseau2 := Argv.getString(1); end; if (Pos(PREFIX_LINE_LOCALITY, MyLine) = 1) then // Localité, commune begin Argv.SplitFrom(MyLine, #9); FCommune := Argv.getString(1); end; if (Pos(PREFIX_LINE_PLACENAME, MyLine) = 1) then // Lieu-dit begin Argv.SplitFrom(MyLine, #9); FLieuDit := Argv.getString(1); end; if (Pos(PREFIX_LINE_COPYRIGHT, MyLine) = 1) then // Copyright begin Argv.SplitFrom(MyLine, #9); FCopyright := Argv.getString(1); end; // Lecture des centerlines case (HasInstructionInclude(INSTRUCTION_INCLUDE_GCP, MyLine, NumLigne, QFichierToInclude)) of tincNO_INCLUDE: // on lit la section basepoints begin if (MyLine = BASEPOINTMARKER) then begin AfficherMessageErreur('--> (%d) - ''%s'' section found',[NumLigne, BASEPOINTMARKER]); while (True) do begin MyLine := LireLigne(); if (MyLine = '') then Continue; if (Pos('#', MyLine) > 0) then Continue; // commentaires if (MyLine = ENDBASEPOINTMARKER) then // si le marqueur de fin de section 'Basepoints' est trouvé, begin TrierBasePointsParIDBaseStation(); // Trier la table des basepoints Break; // puis sortir du while end; self.AddABasePointFromString(MyLine); end; end; //if (Line = BASEPOINTMARKER) then begin end; tincOK_TO_READ: // on inclut le fichier begin FCenterlinesIsIncludeFileGCP := True; FFichierCenterlines := ExtractFileName(QFichierToInclude); AfficherMessageErreur('*** Lecture du fichier include: ' + QFichierToInclude); Result := LireUnFichier(QFichierToInclude); AfficherMessageErreur('--> Resultat: %d', [Result]); end; tincFILE_NOT_FOUND: begin Result := -2; AfficherMessageErreur('*** [%d] %s: %s *** ', [Result, rsERR_MSG_FILE_NOT_FOUND, QFichierToInclude]); Exit; end; tincANY_ERROR: begin Result := -3; AfficherMessageErreur('*** [%d] %s: %s *** ', [Result, rsERR_MSG_IMPORT_CENTERLINE, QFichierToInclude]); Exit; end; end; //*) if (MyLine = IMAGESSECTION) then // lecture images begin AfficherMessageErreur('--> (%d) - ''%s'' section found',[NumLigne, IMAGESSECTION]); while (True) do begin MyLine := LireLigne(); if (MyLine = '') then Continue; if (Pos('#', MyLine)>0) then Continue; // commentaires //LirePolyLigne(MyLine); if (MyLine = ENDIMAGESSECTION) then begin AfficherMessage('--> '''+ ENDSUPERGROUPESSECTION +''' section found'); Break; end; // check sommaire MyIMG.fromLineGCD(MyLine); // := ExtractImageFromStr(MyLine); AddImage(MyIMG); end; // while (True) do begin end; if (MyLine = DRAWERSSECTION) then // lecture dessinateurs (préparatoire au travail collaboratif) begin AfficherMessageErreur('--> (%d) - ''%s'' section found',[NumLigne, DRAWERSSECTION]); while (True) do begin MyLine := LireLigne(); if (MyLine = '') then Continue; if (Pos('#', MyLine)>0) then Continue; // commentaires if (MyLine = ENDDRAWERSSECTION) then begin AfficherMessage('--> '''+ ENDDRAWERSSECTION +''' section found'); Break; end; SD.fromLineGCD(MyLine); // := ExtractSuperGroupeFromStr(MyLine); if (HasAlreadyIDDessinateur(SD.ID)) then SD.ID := self.GetNbDessinateurs(); AddDessinateur(SD); end; // while (True) do begin end; if (MyLine = SUPERGROUPESSECTION) then // lecture super-groupes begin AfficherMessageErreur('--> (%d) - ''%s'' section found',[NumLigne, SUPERGROUPESSECTION]); while (True) do begin MyLine := LireLigne(); if (MyLine = '') then Continue; if (Pos('#', MyLine)>0) then Continue; // commentaires if (MyLine = ENDSUPERGROUPESSECTION) then begin AfficherMessage('--> '''+ ENDSUPERGROUPESSECTION +''' section found'); Break; end; SG.fromLineGCD(MyLine); // := ExtractSuperGroupeFromStr(MyLine); AddSuperGroupe(SG); end; // while (True) do begin end; if (MyLine = GROUPESSECTION) then // lecture groupes begin IdxMaxGroupe := -1; AfficherMessageErreur('--> (%d) - ''%s'' section found',[NumLigne, GROUPESSECTION]); while (True) do begin MyLine := LireLigne(); if (MyLine = '') then Continue; if (Pos('#', MyLine) > 0) then Continue; // commentaires if (MyLine = ENDGROUPESSECTION) then begin AfficherMessage('--> '''+ ENDGROUPESSECTION +''' section found'); Break; end; G.fromLineGCD(MyLine); //:= ExtractGroupeFromStr(MyLine); if (G.IDGroupeEntites > IdxMaxGroupe) then IdxMaxGroupe := G.IDGroupeEntites; AddGroupe(G, false); end; AfficherMessage('%d groupes ; IdxMax = %d', [GetNbGroupes(), IdxMaxGroupe]); end; // lecture scraps LS.Clear; if (MyLine = SCRAPSSECTION) then begin AfficherMessage('--> (%d) - ''%s'' section found',[NumLigne, SCRAPSSECTION]); while (True) do begin MyLine := LireLigne(); if (MyLine = '') then Continue; if (Pos('#', MyLine) > 0) then Continue; // commentaires if (Pos(SCRAP, MyLine ) > 0) then begin try Argv.SplitFrom(MyLine, #9); //# Scrap Parameters: IDScrap, IDGroupe, ColorR, ColorG, ColorB, Transparency (0..255), ZOrder, Name // scrap 1 14 255 126 120 128 0.00 Scrap1 MyScrap.IDGroupe := Argv.getInt32(2, 0); //// StrToIntDef(Argv[2], 0); MyScrap.Couleur.setFrom(Argv.getInt32(3, 255), Argv.getInt32(4, 0), Argv.getInt32(5, 0), Argv.getInt32(6, 128)); MyScrap.Nom := Argv.getString(7); //// Trim(Argv[7]); MyScrap.LastModified := Now(); MyScrap.Empty(); // SetLength(MyScrap.Sommets, 0); // liste provisoire pour les arcs LS.Clear; while (True) do begin MyLine := LireLigne(); if (MyLine = '') then Continue; if (Pos('#', MyLine) > 0) then Continue; // commentaires if (Pos(ENDSCRAP, MyLine) > 0) then Break; LS.Add(MyLine); end; NbAc := LS.Count; MyScrap.setCapacity(NbAc); for i := 0 to MyScrap.getNbVertex() - 1 do begin MyVertex.fromLineGCD(LS.Strings[i]); MyScrap.putVertex(i, MyVertex); // ExtractVertexPolyFromStr(LS.Strings[i])); end; AddScrap(MyScrap, false); except; AfficherMessageErreur('[%d] ** Error reading scrap', [NumLigne]); end; end; if (MyLine = ENDSCRAPSSECTION) then begin AfficherMessage('--> '''+ ENDSCRAPSSECTION +''' section found'); Break; end; end; end; // if Line = POLYGONSECTION; // lecture courbes LS.Clear; if (MyLine = CURVESSECTION) then begin AfficherMessageErreur('--> (%d) - ''%s'' section found',[NumLigne, CURVESSECTION]); while (True) do begin Inc(i); MyLine := LireLigne(); if (MyLine = '') then Continue; if (Pos('#', MyLine)>0) then Continue; // commentaires if (Pos(ENTITYCURVE, MyLine ) > 0) then begin try Argv.SplitFrom(MyLine, #9); CV.IDGroupe := Argv.getInt32(2, 0); /// StrToIntDef(Argv[2], 0); CV.IDStyleCourbe := TNatureObjetCourbe(Argv.getInt32(3, 0));/// TNatureObjetCourbe(StrToIntDef(Argv[3], 0)); CV.Closed := (1 = Argv.getInt32(4, 0)); /// (1 = StrToIntDef(Argv[4], 0)); CV.LastModified := Now(); SetLength(CV.Arcs, 0); // liste provisoire pour les arcs LS.Clear; while (True) do begin MyLine := LireLigne(); if MyLine ='' then Continue; if (Pos('#', MyLine)>0) then Continue; // commentaires if (Pos(ENDENTITYCURVE, MyLine) > 0) then Break; LS.Add(MyLine); end; NbAc := LS.Count; CV.setCapacity(NbAc); for i := 0 to NbAc - 1 do begin QArc.fromLineGCD(LS.Strings[i]); CV.setArc(i, QArc); end; //for i := 0 to NbAc - 1 do CV.setArc(i, ExtractArcPolyFromStr(LS.Strings[i])); //CV := CalcBoundingBoxCourbe(CV); CV.MarkToDelete := false; AddCourbe(CV, false); except; AfficherMessageErreur('[%d] ** Error reading curve', [NumLigne]); end; end; if (MyLine = ENDCURVESSECTION) then begin AfficherMessage('--> '''+ ENDCURVESSECTION +''' section found'); Break; end; end; end; // if Line = CURVESSECTION; // lecture polylignes LS.Clear; if (MyLine = POLYLINESSECTION) then begin AfficherMessageErreur('--> (%d) - ''%s'' section found',[NumLigne, POLYLINESSECTION]); while (True) do begin MyLine := LireLigne(); if (MyLine = '') then Continue; if (Pos('#', MyLine) > 0) then Continue; // commentaires if (Pos(ENTITYPOLYLINE, MyLine ) > 0) then begin try Argv.SplitFrom(MyLine, #9); PLL.IDGroupe := Argv.getInt32(2, 0); //// StrToIntDef(Argv[2], 0); PLL.IDStylePolyLine := TNatureObjetCourbe(Argv.getInt32(3, 0)); //// TNatureObjetCourbe(StrToIntDef(Argv[3], 0)); PLL.Closed := (1 = Argv.getInt32(4, 0)); ///(1 = StrToIntDef(Argv[4], 0)); PLL.LastModified := Now(); SetLength(PLL.Sommets, 0); // liste provisoire pour les arcs LS.Clear; while (True) do begin MyLine := LireLigne(); if (MyLine = '') then Continue; if (Pos('#', MyLine) > 0) then Continue; // commentaires if (Pos(ENDENTITYPOLYLINE, MyLine) > 0) then Break; LS.Add(MyLine); end; NbAc := LS.Count; PLL.setCapacity(NbAc); for i := 0 to PLL.getNbVertex() - 1 do begin MyVertex.fromLineGCD(LS.Strings[i]); PLL.putVertex(i, MyVertex); //ExtractVertexPolyFromStr(LS.Strings[i])); end; PLL.MarkToDelete := false; AddPolyLigne(PLL, false); except; AfficherMessageErreur('[%d] ** Error reading polyline %d', [NumLigne, GetNbPolylignes()]); end; end; if (MyLine = ENDPOLYLINESSECTION) then begin AfficherMessage('--> '''+ ENDPOLYLINESSECTION +''' section found'); Break; end; end; end; // if Line = POLYLINESSECTION; // lecture polygones LS.Clear; if (MyLine = POLYGONSECTION) then begin AfficherMessageErreur('--> (%d) - ''%s'' section found',[NumLigne, POLYGONSECTION]); while (True) do begin MyLine := LireLigne(); if (MyLine = '') then Continue; if (Pos('#', MyLine) > 0) then Continue; // commentaires if (Pos(ENTITYPOLYGON, MyLine ) > 0) then begin try Argv.SplitFrom(MyLine, #9); PLG.IDGroupe := Argv.getInt32(2); //// StrToIntDef(Argv[2], 0); PLG.IDStylePolygone := TNatureObjetPolygone(Argv.getInt32(3)); //// TNatureObjetPolygone(StrToIntDef(Argv[3], 0)); PLG.LastModified := Now(); ////StrToDateTimeDef(Argv[4], Now()); PLG.Empty(); // liste provisoire pour les sommets LS.Clear; while (True) do begin MyLine := LireLigne(); if (MyLine = '') then Continue; if (Pos('#', MyLine) > 0) then Continue; // commentaires if (Pos(ENDENTITYPOLYGON, MyLine) > 0) then Break; LS.Add(MyLine); end; NbAc := LS.Count; PLG.Redim(NbAc); for i := 0 to PLG.getNbVertex() - 1 do begin MyVertex.fromLineGCD(LS.Strings[i]); PLG.putVertex(i, MyVertex); //ExtractVertexPolyFromStr(LS.Strings[i])); end; PLG.MarkToDelete := false; AddPolygone(PLG, false); except; AfficherMessageErreur('[%d] ** Error reading polygon', [NumLigne]); end; end; if (MyLine = ENDPOLYGONSECTION) then begin AfficherMessage('--> '''+ ENDPOLYGONSECTION +''' section found'); Break; end; end; end; // if Line = POLYGONSECTION; // lecture ligne if (MyLine = LINESECTION) then begin AfficherMessageErreur('--> (%d) - ''%s'' section found',[NumLigne, LINESECTION]); while (True) do begin MyLine := LireLigne(); if (MyLine = '') then Continue; if (Pos('#', MyLine)>0) then Continue; // commentaires if (MyLine = ENDLINESECTION) then begin AfficherMessage('--> '''+ ENDLINESECTION +''' section found'); Break; end; MySimpleLigne.fromLineGCD(NumLigne, MyLine);//:= ExtractSimpleLineFromStr(NumLigne, MyLine); AddSimpleLigne(MySimpleLigne, false); end; end; // if MyLine = LINESECTION; if (MyLine = TEXTSECTION) then begin AfficherMessageErreur('--> (%d) - ''%s'' section found',[NumLigne, TEXTSECTION]); while (True) do begin MyLine := LireLigne(); if (MyLine = '') then Continue; if (Pos('#', MyLine)>0) then Continue; // commentaires if (MyLine = ENDTEXTSECTION) then begin AfficherMessage('--> '''+ ENDTEXTSECTION +''' section found'); Break; end; MyTexte.fromLineGCD(MyLine); AddTexte(MyTexte, false); //ExtractObjTexteFromStr(MyLine), false); end; end; // if MyLine = TEXTSECTION; if (MyLine = PONCTOBJSECTION) then begin AfficherMessageErreur('--> (%d) - ''%s'' section found',[NumLigne, PONCTOBJSECTION]); while (True) do begin MyLine := LireLigne(); if (MyLine = '') then Continue; if (Pos('#', MyLine)>0) then Continue; // commentaires if (MyLine = ENDPONCTOBJSECTION) then begin AfficherMessage('--> '''+ PONCTOBJSECTION +''' section found'); Break; end; MySymbole.fromLineGCD(MyLine); AddSymbole(MySymbole, false); //ExtractSymbolFromStr(MyLine), false); end; end; // if Line = PONCTOBJSECTION; end; // while général not eof //***************************************** FCenterLines.TrierBasePointsParIDBaseStation(); // tri par index TrierGroupesByZOrder(); // tri des groupes par altitudes FCenterLines.MetaFiltrer(''); // filtres SetMiniEtMaxi(); // mini et maxi CalcBoundingBoxAllGroupes(); // calcul des boites englobantes des groupes //****************************************** AfficherMessageErreur('%d images', [GetNbImages()]); AfficherMessage('%d supergroupes', [GetNbSuperGroupes()]); AfficherMessage('%d groupes', [GetNbGroupes()]); AfficherMessage('%d scraps', [GetNbScraps()]); AfficherMessage('%d courbes', [GetNbCourbes()]); AfficherMessage('%d polylignes', [GetNbPolylignes()]); AfficherMessage('%d polygones', [GetNbPolygones()]); AfficherMessage('%d lignes', [GetNbSimpleLignes()]); AfficherMessage('%d symboles', [GetNbSymboles()]); AfficherMessage('%d labels', [GetNbTextes()]); //******************************************** AfficherMessage(FDocumentName + ' ouvert avec succes'); Result := 0; LS.Clear; exit; finally CloseFile(fp); freeandNil(LS); end; end; begin Result := False; // attribution du nom du document FDocumentName := FichierGCD; // dossier contenant le document FDossierDuDocument := ExtractFileDir(FichierGCD); // purge des listes FCenterLines.InitialiseCenterLines; FCenterlinesIsIncludeFileGCP := false; PurgerListesObjets(); AfficherMsgClass(self, 'LoadFromFileExt(%s)',[ FichierGCD]); try QFichierCorrect := LireUnFichier(FichierGCD); case QFichierCorrect of -1: AfficherMessageErreur('--> Echec en lecture du fichier principal'); -2: AfficherMessageErreur('--> Un des fichiers appelés par $INCLUDE est introuvable'); -3: AfficherMessageErreur('--> Echec en lecture de fichiers à inclure'); 0: // Lecture OK begin if (self.GetNbDessinateurs() = 0) then begin MyDessinateur.setFrom(0, 'Dessinateur0', 'Le dessinateur par défault'); AddDessinateur(MyDessinateur); end; if (self.GetNbSuperGroupes() = 0) then begin MySuperGroupe.Couleur := clBlue; MySuperGroupe.NomSuperGroupe := 'SuperGroupe0'; MySuperGroupe.Displayed := True; MySuperGroupe.ListeGroupes.Redim(0); AddSuperGroupe(MySuperGroupe); end; if (self.GetNbGroupes() = 0) then begin MyGroupe.IDGroupeEntites := 0; MyGroupe.NomGroupe := 'Groupe0'; MyGroupe.CouleurGroupe := clBlue; MyGroupe.DecalageXY.Empty(); MyGroupe.DateLastModif := Now(); MyGroupe.Filtres := ''; MyGroupe.Visible := true; AddGroupe(MyGroupe, false); end; end; else AfficherMessageErreur('Erreur ouverture du fichier: %d', [QFichierCorrect]); end; Result := (QFichierCorrect = 0); AfficherMessageErreur('Code retour: %d', [QFichierCorrect]); except pass; end; end; function TDocumentDessin.LoadEncryptedFile(const QFilename: TStringDirectoryFileName; const Password: string): boolean; begin result := false; AfficherMsgClass(self, 'LoadEncryptedFile(%s)', [QFilename]); end;