-- This program is the last attempt of artificial intelligency with Ada.
-- Elhoim is Copyright (C) 2023 Manuel ; 
--
--   This program is free software; you can redistribute it and/or modify
--   it under the terms of the GNU General Public License as published by
--   the Free Software Foundation; either version 2 of the License, or
--   (at your option) any later version.
--
--   This program is distributed in the hope that it will be useful,
--   but WITHOUT ANY WARRANTY; without even the implied warranty of
--   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--   GNU General Public License for more details.
--
--   You should have received a copy of the GNU General Public License
--   along with this program; if not, write to the Free Software
--   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
--
-- Date := "2023-05-05 17:57:22"
-- Version := "0.1.4b"
package body Lib.Graphs is
   
   
   procedure Export_Canvas_Menu(Action, Main_Window : Address) is
      pragma Unreferenced (Action);
      
      The_Surface : Cairo_Surface;
      Cr          : Cairo_Context;
      Status      : Cairo_Status;
   begin
      
      The_Surface := Create(Cairo_Format_ARGB32,
                            To_Pointer(Main_Window).Gnose_Interface.Graph_Set(Project_Define).X_Ads,
                            To_Pointer(Main_Window).Gnose_Interface.Graph_Set(Project_Define).Y_Ads);
      Cr := Create(The_Surface);            
      Draw_All(To_Pointer(Main_Window).Gnose_Interface.Graph_Set(Project_Define).Canvas, Cr);
      The_Surface := Get_Target(Cr);
      Status := Cairo.PNG.Write_To_Png(The_Surface, "Gnostic.png");      
   end Export_Canvas_Menu;               
   
   
   procedure Reload_Project(Object : in Object_Pointer);   
   
   procedure Reload_Menu(Action, Main_Window : Address) is
      pragma Unreferenced (Action);
      
      Gnostic : constant Gnose_Access := To_Pointer(Main_Window).all'Access;
   begin
      
      if Gnostic.System_Step = reload then
         Reload_Project(To_Pointer(Main_Window));
         if Gnostic.Exit_Result.Success then
	    
            -- Going to Update :
            Gnostic.System_Step := Update;
            Insert_With_Tag(Gnostic.Gnose_Interface.System_Text_Buffer, "", "Going to next step : " & System_Step_Enum'image(Gnostic.System_Step));
         else
            Gnostic.System_Step := On_Error;
            Insert_With_Tag(Gnostic.Gnose_Interface.System_Text_Buffer, "", "Going to next step : " & System_Step_Enum'image(Gnostic.System_Step));
         end if;      

      else
         declare
	    
            Message : constant Message_Enum := System_Step_Message;
            Message_Window : Message_Timeout_Window_Type(Message);
         begin
            Message_Window.Previsious_Step := Gnostic.System_Step;
            Message_Window.Current_Step := Reload;
            Message_Window.End_Time := Clock + Gnostic.Context.Neural_Params.User_Wait;
	    
            Initialize_Message_Window(Message_Window, gtk_window(Gnostic.Gnose_Interface));
            if not Message_Window.Success then
               if Gnostic.Context.System_Params.Self_Executed then
                  Remove(Gnostic.Self_Execute_Timeout);
               end if;	 
               Gnostic.Context.System_Params.Self_Executed := False;
            else
               Reload_Project(To_Pointer(Main_Window));
            end if;
            if Gnostic.Exit_Result.Success then
	       
               -- Going to Update :
               Gnostic.System_Step := Update;
               Insert_With_Tag(Gnostic.Gnose_Interface.System_Text_Buffer, "", "Going to next step : " & System_Step_Enum'image(Gnostic.System_Step));
            else
               Gnostic.System_Step := On_Error;
               Insert_With_Tag(Gnostic.Gnose_Interface.System_Text_Buffer, "", "Going to next step : " & System_Step_Enum'image(Gnostic.System_Step));
            end if;      

         end;
	 
      end if;
      
   end Reload_Menu;
   
      procedure Main_Destroy (Window : access Gtk_Window_record'Class;
                           Gnostic : in Gnose_access) is
      
   begin
      
      if Gnostic /= null then
         Text_Io.Put_Line("Going to halt System...");
         Gnostic.Process.Halt;
         abort Gnostic.Process;
         Text_Io.Put_Line("System halted.");	 
      else
         Text_Io.Put_Line("Gnostic null");
      end if;      
      Gtk.Main.Main_Quit;
   end Main_Destroy;
   
      Layout : Pango_Layout;
   
   procedure Draw
     (Item   : access Display_Item_Record;
      Cr     : Cairo_Context)
   is
   begin
      Gdk.Cairo.Set_Source_Color (Cr, Item.Color);
      Cairo.Rectangle
        (Cr, 0.5, 0.5, Gdouble (Item.W) - 1.0, Gdouble (Item.H) - 1.0);
      Cairo.Fill (Cr);

      Gdk.Cairo.Set_Source_Color (Cr, Item.Title);
      Rectangle
        (Cr, 0.5, 0.5, Gdouble (Item.W) - 1.0, Gdouble (Item.H) - 1.0);
      Cairo.Stroke (Cr);

      Set_Text (Layout, Display_Item (Item).Name);
      Cairo.Move_To (Cr, 10.0, 10.0);
      Pango.Cairo.Show_Layout (Cr, Layout);
   end Draw;


   
   
   
   Max_Colors : constant := 20;
   
   type Color_Type is range 1 .. Max_Colors;
   
   type String_Access is access String;
   Color_Names : constant array (Color_Type) of String_Access :=
     (new String'("forest green"),
      new String'("red"),
      new String'("blue"),
      new String'("yellow"),
      new String'("peach puff"),
      new String'("azure"),
      new String'("seashell"),
      new String'("lavender"),
      new String'("grey"),
      new String'("turquoise"),
      new String'("khaki"),
      new String'("tan"),
      new String'("orange red"),
      new String'("MediumPurple"),
      new String'("ivory1"),
      new String'("DeepSkyBlue1"),
      new String'("burlywood1"),
      new String'("wheat1"),
      new String'("orange1"),
      new String'("pink"));

   Colors : array (Color_Type) of Gdk_Color;
   
   
   procedure Initialize_Main_Item
     (Item   : access Display_Item_Record'Class;
      Canvas : access Interactive_Canvas_Record'Class;
      Name   : in String;
      Filename   : in String)
   is
      Width : constant Gint := Gint(Name'Length) * 10;
   begin
      
      Move(Name, Item.Name, Ada.Strings.Error, Left, ' ');
      Move(Filename, Item.Filename, Ada.Strings.Error, Left, ' ');
      
      Item.Canvas := Interactive_Canvas (Canvas);

      Item.Color := Colors(3);

      Item.W := Width;

      Item.H := 30;

      Item.Num := 1;
      
      Set_Screen_Size (Item, Item.W, Item.H);

   end Initialize_Main_Item;
   
   procedure Initialize_Lib_Item
     (Item   : access Display_Item_Record'Class;
      Canvas : access Interactive_Canvas_Record'Class;
      Name   : in String;
      Filename   : in String;
      Color  : in Color_Type)
   is
      Width : constant Gint := Gint(Name'Length) * 10;
   begin
      
      Move(Name, Item.Name, Ada.Strings.Error, Left, ' ');
      Move(Filename, Item.Filename, Ada.Strings.Error, Left, ' ');
      
      Item.Canvas := Interactive_Canvas (Canvas);

      Item.Color := Colors(Color);
      
      Item.W := Width;
      
      Item.H := 30;
      
      Item.Num := 2;
      
      Set_Screen_Size (Item, Item.W, Item.H);
   end Initialize_Lib_Item;
   
   
   ---------------------
   -- Add_*_Item --
   ---------------------
   
   procedure Add_Main_Item
     (Canvas : access Interactive_Canvas_Record'Class;
      Name   : in String;
      Filename   : in String;
      Tab        : in out Item_Array_Type;
      Index      : in out Natural)
   is
      Item : constant Display_Item := new Display_Item_Record;
      
   begin
      
      Initialize_Main_Item (Item, Canvas, Name, Filename);
      Tab(Index+1) := Item;
      Index := Index + 1;
      
      Put (Canvas, Item, 800, 10);
      Refresh_Canvas (Canvas);
      Show_Item (Canvas, Item);
   end Add_Main_Item;
   
   
   
   procedure Add_Lib_Item
     (Canvas : access Interactive_Canvas_Record'Class;
      Name      : in String;
      Filename   : in String;
      X, Y      : in Gint;
      Tab        : in out Item_Array_Type;
      Index      : in out Natural;
      Color  : in Color_Type)
   is
      Item : constant Display_Item := new Display_Item_Record;      
   begin
      
      Initialize_Lib_Item (Item, Canvas, Name, Filename, color);
      Tab(Index+1) := Item;
      Index := Index + 1;
      
      Put (Canvas, Item, X, Y);
      Refresh_Canvas (Canvas);
      Show_Item (Canvas, Item);
   end Add_Lib_Item;
   
   
   
   procedure Add_Canvas_Link
     (Canvas : access Interactive_Canvas_Record'Class;
      Item1, Item2 : access Canvas_Item_Record'Class; Text : String := "");
   --  Add a link between Item1 and Item2
   
   ---------------------
   -- Add_Canvas_Link --
   ---------------------

   procedure Add_Canvas_Link
     (Canvas : access Interactive_Canvas_Record'Class;
      Item1, Item2 : access Canvas_Item_Record'Class; Text : String := "")
   is
      Link : constant Canvas_Link := new Canvas_Link_Record;
   begin
      Add_Link (Canvas, Link, Item1, Item2, End_Arrow, Text);
   end Add_Canvas_Link;

   
   
   -----------
   -- Clear --
   -----------

   procedure Clear_Canvas (Canvas : access Interactive_Canvas_Record'Class) is
      function Remove_Internal
        (Canvas : access Interactive_Canvas_Record'Class;
         Item   : access Canvas_Item_Record'Class) return Boolean is
      begin
         Remove (Canvas, Item);
         return True;
      end Remove_Internal;
      
   begin
      For_Each_Item (Canvas, Remove_Internal'Unrestricted_Access);
      Refresh_Canvas (Canvas);      
      
   end Clear_Canvas;
   
   
   procedure Reverse_Canvas_Constructor(Canvas : in Canvas_Record_Access;	
                                        Units : in Unit_Array_Type;
                                        Last  : in Positive;
                                        As_Lib  : Boolean);
   
   procedure Reverse_Canvas_Menu(Action, Main_Window : Address) is
      pragma Unreferenced(Action);
      Object : constant Gnose_Access := To_Pointer(Main_Window).all'Access;      
   begin
      if Object.Gnose_Interface.Graph_set(Project_Define).Canvas/= null then
         Clear_Canvas(Object.Gnose_Interface.Graph_set(Project_Define).Canvas);
      end if;
      if Object.Context.Project.Proj_Library.Unit_Index > 0 then	 	 
         Reverse_Canvas_Constructor
           (Object.Gnose_Interface.Graph_Set(Project_Define),
            Object.Context.Project.Proj_Library.Library_Unit,
            Object.Context.Project.Proj_Library.Unit_Index,
            False
           );
      end if;
   end Reverse_Canvas_Menu;
   
   
   
   procedure Reverse_Canvas_Constructor(Canvas : in Canvas_Record_Access;	
                                        Units : in Unit_Array_Type;
                                        Last  : in Positive;
                                        As_Lib  : Boolean) is
      Start_Index : Positive := 2;
   begin
      Canvas.X_Ads := 400;
      Canvas.Y_ads := 50;
      
      Canvas.X_Adb := 200;
      Canvas.Y_Adb := 100;
      
      
      Canvas.Item_Last := 0;
      
      ----------------------------------------------------------------------
      -- Adding Item to Canvas :                                          --
      
      if not As_Lib then

         Add_Main_Item(
                       Canvas.Canvas,
                       Units(1).Unit_Name
                       (1..Index_Non_Blank(Units(1).Unit_Name, Backward)),
                       Units(1).File_Name,		      
                       Canvas.Item_Array,
                       Canvas.Item_Last
                      );
      else
         Start_Index := 1;
      end if;
      
      if Last > 1 then
         for I in Start_index..Last loop
            --Text_Io.Put_Line("item 4.1");
            declare
               Unitname : constant String :=
                 Units(I).Unit_Name
                 (1..Index_Non_Blank(Units(I).Unit_Name, Backward));
	       
               Extension : constant String := 
                 File_Extension(units(I).Unit_Name(1..Index_Non_Blank(units(I).Unit_Name, Backward)));
	       
            begin
               --Text_Io.Put_Line("item 4.2");
               if Extension = ".ads" then
                  Add_Lib_Item
                    (Canvas.Canvas,
                     Unitname,
                     Units(I).File_Name,
                     Canvas.X_ads, 
                     Canvas.Y_ads,		  
                     Canvas.Item_Array,
                     Canvas.Item_Last,
                     Color => 10);
                  Canvas.X_ads := Canvas.X_ads + 50;
                  Canvas.Y_ads := Canvas.Y_ads + 70;
                  --Text_Io.Put_Line("item 4.3");
               else
                  Add_Lib_Item
                    (Canvas.Canvas,
                     Unitname,
                     Units(I).File_Name,
                     Canvas.X_adb, 
                     Canvas.Y_adb,		  
                     Canvas.Item_Array,
                     Canvas.Item_Last,
                     Color => 19);
                  Canvas.X_adb := Canvas.X_adb + 25;
                  Canvas.Y_adb := Canvas.Y_adb + 70;
                  --Text_Io.Put_Line("item 4.4");
               end if;
	       
	       
            end;
         end loop;
      end if;

      ----------------------------------------------------------------------
      -- Adding Link between Item to Canvas.
      
      if Canvas.Item_Last > 0 then
         for I in reverse 1..Canvas.Item_Last loop
            declare
	       
               Extension : constant String := File_Extension(Canvas.Item_Array(I).Name
                                                             (1..Index_Non_Blank(Canvas.Item_Array(I).Name, Backward)));
               Basename : constant String := Base_Name(Canvas.Item_Array(I).Name
                                                       (1..Index_Non_Blank(Canvas.Item_Array(I).Name, Backward)),
                                                       extension);
            begin
	       
               if Extension = ".adb" then		  
                  declare
                     Body_Item : constant Display_Item := Canvas.Item_Array(I);
                  begin
		     
                     for J in 1..Canvas.Item_Last loop
			
                        declare
			   
                           Item_Extension : constant String := File_Extension(Canvas.Item_Array(J).Name
                                                                              (1..Index_Non_Blank(Canvas.Item_Array(J).Name, Backward)));
                           Item_Basename : constant String := Base_Name(Canvas.Item_Array(J).Name
                                                                        (1..Index_Non_Blank(Canvas.Item_Array(J).Name, Backward)),
                                                                        Item_Extension);
                        begin
			   
                           if Item_Basename = Basename and Item_Extension = ".ads" then
			      
                              declare
				 
                                 Spec_Item : constant Display_Item := Canvas.Item_Array(J);
                              begin
				 
                                 Add_Canvas_Link(Canvas.Canvas, Body_Item, Spec_Item, "implementation");
                              end;
                           end if;
                        end;
			
                     end loop;
                  end;
               end if;
	       
	       
               declare
                  File : Wide_Text_Io.File_Type;
                  Filename : constant String := Canvas.Item_Array(I).Filename
                    (1..Index_Non_Blank(Canvas.Item_Array(I).Filename, Backward));
               begin
		  
                  Wide_Text_Io.Open(File, Wide_Text_Io.In_File, Filename, Form => "WCEM=8");
		  
                  while not Wide_Text_Io.End_Of_File(File) loop
		     
                     declare
			
                        Line : constant Wide_String := UTF_Encoding.Wide_Strings.Decode(Wide_Text_Io.Get_Line(File));
			
                        The_Index : Natural := 0;
			

			
                     begin
                        --Wide_Text_Io.Put_Line(Line);
                        if Wide_Fixed.Index(Line, "package") /= 0 or
                          Wide_Fixed.Index(Line, "procedure") /= 0 or
                          Wide_Fixed.Index(Line, "function") /= 0 or
                          Wide_Fixed.Index(Line, "genric")/= 0 then
                           exit;
                        end if;
                        if Line'Length > 0 then
			   
                           The_Index := Wide_Fixed.Index(Line, "--");
                           if ((The_Index /= 0) and then			     
                               Wide_Fixed.Index(Line, "with") > The_Index) then
                              null;
                           elsif Wide_Fixed.Index(Line, "with") /= 0 then
                              The_Index := Wide_Fixed.Index(Line, "with");
                              while The_Index /= 0 loop
				 
				 
                                 declare
				    
                                    End_Of : constant Natural := Wide_Fixed.Index(Line, ";", The_index);
                                    Section : constant String :=
                                      Handling.To_Lower
                                        (Handling.To_String
                                           (Line(Wide_Fixed.Index_Non_Blank(Line, The_Index + 5)..End_Of -1)));

                                    Section_Dot : constant Natural := Index(Section, ".");
                                 begin
                                    if Section_Dot /= 0 then
				       
				       
                                       for J in 1..Canvas.Item_Last loop
					  
                                          declare
					     
                                             Item_Extension : constant String := File_Extension(Canvas.Item_Array(J).Name
                                                                                                (1..Index_Non_Blank(Canvas.Item_Array(J).Name, Backward)));
                                             Item_Basename : constant String := Base_Name(Canvas.Item_Array(J).Name
                                                                                          (1..Index_Non_Blank(Canvas.Item_Array(J).Name, Backward)),
                                                                                          Item_Extension);
					     
                                             Doted_Basename : constant String := Translate(Item_Basename, Maps.To_Mapping("-", "."));
					     
					     
                                          begin
					     
                                             if Doted_Basename = section then
                                                if Item_Extension = ".ads" then
						   
                                                   declare
						      
                                                      Spec_Item : constant Display_Item := Canvas.Item_Array(J);
                                                   begin
						      
                                                      Add_Canvas_Link
                                                        (Canvas.Canvas,
                                                         Canvas.Item_Array(I), 
                                                         Spec_Item, Basename & " depend of " & section);

                                                   end;
                                                end if;
                                             end if;
					     
                                          end;
					  
                                       end loop;
				       
				       
                                    else 
                                       for J in 1..Canvas.Item_Last loop
					  
                                          declare
					     
                                             Item_Extension : constant String := File_Extension(Canvas.Item_Array(J).Name
                                                                                                (1..Index_Non_Blank(Canvas.Item_Array(J).Name, Backward)));
                                             Item_Basename : constant String := Base_Name(Canvas.Item_Array(J).Name
                                                                                          (1..Index_Non_Blank(Canvas.Item_Array(J).Name, Backward)),
                                                                                          Item_Extension);
					     
                                             Doted_Basename : constant String := Translate(Item_Basename, Maps.To_Mapping("-", "."));
					     
					     
                                          begin
					     
                                             if Doted_Basename = section then
                                                if Item_Extension = ".ads" then
						   
                                                   declare
						      
                                                      Spec_Item : constant Display_Item := Canvas.Item_Array(J);
                                                   begin
						      
                                                      Add_Canvas_Link
                                                        (Canvas.Canvas,
                                                         Canvas.Item_Array(I),
                                                         Spec_Item, Basename & " depend of " & section);
                                                   end;
						   
                                                end if;						   
                                             end if;
					     
                                          end;
					  
                                       end loop;
                                    end if;
                                 end;
                                 if The_Index + 5 < Line'Length then
                                    The_Index := Wide_Fixed.Index(Line, "with", The_Index + 5);			
				    
                                 end if;
				 
                              end loop;
                           end if;
                        end if;
                     end;
                  end loop;
		  
                  Wide_Text_Io.Close(File);
               end;

	       
            end;
	    
         end loop;
      end if;
      --Text_Io.Put_Line("End of reverse Graph construction");
   end Reverse_Canvas_Constructor;

   procedure Canvas_Project_Constructor(Canvas : in Canvas_Record_Access;	
                                        Units : in Unit_Array_Type;
                                        Last  : in Positive;
                                        As_Lib  : Boolean) is
      
      
      
      Start_Index : Positive := 2;
   begin            
      
      Canvas.X_Ads := 400;
      Canvas.Y_ads := 50;
      
      Canvas.X_Adb := 200;
      Canvas.Y_Adb := 100;
      
      
      Canvas.Item_Last := 0;
      
      ----------------------------------------------------------------------
      -- Adding Item to Canvas :                                          --
      
      if not As_Lib then

         Add_Main_Item(
                       Canvas.Canvas,
                       Units(1).Unit_Name
                       (1..Index_Non_Blank(Units(1).Unit_Name, Backward)),
                       Units(1).File_Name,		      
                       Canvas.Item_Array,
                       Canvas.Item_Last
                      );
      else
         Start_Index := 1;
      end if;
      
      if Last > 1 then
         for I in reverse Start_index..Last loop
            --Text_Io.Put_Line("item 4.1");
            declare
               Unitname : constant String :=
                 Units(I).Unit_Name
                 (1..Index_Non_Blank(Units(I).Unit_Name, Backward));
	       
               Extension : constant String := 
                 File_Extension(units(I).Unit_Name(1..Index_Non_Blank(units(I).Unit_Name, Backward)));
	       
            begin
               --Text_Io.Put_Line("item 4.2");
               if Extension = ".ads" then
                  Add_Lib_Item
                    (Canvas.Canvas,
                     Unitname,
                     Units(I).File_Name,
                     Canvas.X_ads, 
                     Canvas.Y_ads,		  
                     Canvas.Item_Array,
                     Canvas.Item_Last,
                     Color => 10);
                  Canvas.X_ads := Canvas.X_ads + 50;
                  Canvas.Y_ads := Canvas.Y_ads + 70;
                  --Text_Io.Put_Line("item 4.3");
               else
                  Add_Lib_Item
                    (Canvas.Canvas,
                     Unitname,
                     Units(I).File_Name,
                     Canvas.X_adb, 
                     Canvas.Y_adb,		  
                     Canvas.Item_Array,
                     Canvas.Item_Last,
                     Color => 19);
                  Canvas.X_adb := Canvas.X_adb + 25;
                  Canvas.Y_adb := Canvas.Y_adb + 70;
                  --Text_Io.Put_Line("item 4.4");
               end if;
	       
	       
            end;
         end loop;
      end if;

      ----------------------------------------------------------------------
      -- Adding Link between Item to Canvas.
      
      if Canvas.Item_Last > 0 then
         for I in reverse 1..Canvas.Item_Last loop
            declare
	       
               Extension : constant String := File_Extension(Canvas.Item_Array(I).Name
                                                             (1..Index_Non_Blank(Canvas.Item_Array(I).Name, Backward)));
               Basename : constant String := Base_Name(Canvas.Item_Array(I).Name
                                                       (1..Index_Non_Blank(Canvas.Item_Array(I).Name, Backward)),
                                                       extension);
            begin
	       
               if Extension = ".adb" then		  
                  declare
                     Body_Item : constant Display_Item := Canvas.Item_Array(I);
                  begin
		     
                     for J in 1..Canvas.Item_Last loop
			
                        declare
			   
                           Item_Extension : constant String := File_Extension(Canvas.Item_Array(J).Name
                                                                              (1..Index_Non_Blank(Canvas.Item_Array(J).Name, Backward)));
                           Item_Basename : constant String := Base_Name(Canvas.Item_Array(J).Name
                                                                        (1..Index_Non_Blank(Canvas.Item_Array(J).Name, Backward)),
                                                                        Item_Extension);
                        begin
			   
                           if Item_Basename = Basename and Item_Extension = ".ads" then
			      
                              declare
				 
                                 Spec_Item : constant Display_Item := Canvas.Item_Array(J);
                              begin
				 
                                 Add_Canvas_Link(Canvas.Canvas, Body_Item, Spec_Item, "implementation");
                              end;
                           end if;
                        end;
			
                     end loop;
                  end;
               end if;
	       
	       
               declare
                  File : Wide_Text_Io.File_Type;
                  Filename : constant String := Canvas.Item_Array(I).Filename
                    (1..Index_Non_Blank(Canvas.Item_Array(I).Filename, Backward));
               begin
		  
                  Wide_Text_Io.Open(File, Wide_Text_Io.In_File, Filename, Form => "WCEM=8");
		  
                  while not Wide_Text_Io.End_Of_File(File) loop
		     
                     declare
			
                        Line : constant Wide_String := UTF_Encoding.Wide_Strings.Decode(Wide_Text_Io.Get_Line(File));
			
                        The_Index : Natural := 0;
			

			
                     begin
                        --Wide_Text_Io.Put_Line(Line);
                        if Wide_Fixed.Index(Line, "package") /= 0 or
                          Wide_Fixed.Index(Line, "procedure") /= 0 or
                          Wide_Fixed.Index(Line, "function") /= 0 or
                          Wide_Fixed.Index(Line, "genric")/= 0 then
                           exit;
                        end if;
                        if Line'Length > 0 then
			   
                           The_Index := Wide_Fixed.Index(Line, "--");
                           if ((The_Index /= 0) and then			     
                               Wide_Fixed.Index(Line, "with") > The_Index) then
                              null;
                           elsif Wide_Fixed.Index(Line, "with") /= 0 then
                              The_Index := Wide_Fixed.Index(Line, "with");
                              while The_Index /= 0 loop
				 
				 
                                 declare
				    
                                    End_Of : constant Natural := Wide_Fixed.Index(Line, ";", The_index);
                                    Section : constant String :=
                                      Handling.To_Lower
                                        (Handling.To_String
                                           (Line(Wide_Fixed.Index_Non_Blank(Line, The_Index + 5)..End_Of -1)));

                                    Section_Dot : constant Natural := Index(Section, ".");
                                 begin
                                    if Section_Dot /= 0 then
				       
				       
                                       for J in 1..Canvas.Item_Last loop
					  
                                          declare
					     
                                             Item_Extension : constant String := File_Extension(Canvas.Item_Array(J).Name
                                                                                                (1..Index_Non_Blank(Canvas.Item_Array(J).Name, Backward)));
                                             Item_Basename : constant String := Base_Name(Canvas.Item_Array(J).Name
                                                                                          (1..Index_Non_Blank(Canvas.Item_Array(J).Name, Backward)),
                                                                                          Item_Extension);
					     
                                             Doted_Basename : constant String := Translate(Item_Basename, Maps.To_Mapping("-", "."));
					     
					     
                                          begin
					     
                                             if Doted_Basename = section then
                                                if Item_Extension = ".ads" then
						   
                                                   declare
						      
                                                      Spec_Item : constant Display_Item := Canvas.Item_Array(J);
                                                   begin
						      
                                                      Add_Canvas_Link
                                                        (Canvas.Canvas,
                                                         Canvas.Item_Array(I), 
                                                         Spec_Item, Basename & " depend of " & section);

                                                   end;
                                                end if;
                                             end if;
					     
                                          end;
					  
                                       end loop;
				       
				       
                                    else 
                                       for J in 1..Canvas.Item_Last loop
					  
                                          declare
					     
                                             Item_Extension : constant String := File_Extension(Canvas.Item_Array(J).Name
                                                                                                (1..Index_Non_Blank(Canvas.Item_Array(J).Name, Backward)));
                                             Item_Basename : constant String := Base_Name(Canvas.Item_Array(J).Name
                                                                                          (1..Index_Non_Blank(Canvas.Item_Array(J).Name, Backward)),
                                                                                          Item_Extension);
					     
                                             Doted_Basename : constant String := Translate(Item_Basename, Maps.To_Mapping("-", "."));
					     
					     
                                          begin
					     
                                             if Doted_Basename = section then
                                                if Item_Extension = ".ads" then
						   
                                                   declare
						      
                                                      Spec_Item : constant Display_Item := Canvas.Item_Array(J);
                                                   begin
						      
                                                      Add_Canvas_Link
                                                        (Canvas.Canvas,
                                                         Canvas.Item_Array(I),
                                                         Spec_Item, Basename & " depend of " & section);
                                                   end;
						   
                                                end if;						   
                                             end if;
					     
                                          end;
					  
                                       end loop;
                                    end if;
                                 end;
                                 if The_Index + 5 < Line'Length then
                                    The_Index := Wide_Fixed.Index(Line, "with", The_Index + 5);			
				    
                                 end if;
				 
                              end loop;
                           end if;
                        end if;
                     end;
                  end loop;
		  
                  Wide_Text_Io.Close(File);
               end;

	       
            end;
	    
         end loop;
      end if;
      --Text_Io.Put_Line("End of Graph construction");
      
   end Canvas_Project_Constructor;
   
   
   ----------------------------------------------------------
   -- Reload Project...                                    --
   ----------------------------------------------------------
   procedure Reload_Project(Object : in Object_Pointer) is
   begin
      if Object.Context.Project /= null and then Object.Context.Project.Project_Name /= null then
         loop
            declare
               Child : constant Gtk.Widget.Gtk_Widget := Get_Child(Object.Gnose_Interface.Language_Set(Project_Define).box, 0);
            begin
               if Gtk.Widget."/="(Child,null) then
                  Remove(Object.Gnose_Interface.Language_Set(Project_Define).box, Child);
               else
                  exit;
               end if;
            end;
         end loop;
	 
      end if;
      
      Agnose.Load_Project(Object.Context.all, Ada_Path, Gtk_Path, Aws_Path, Pro_Path);
      
      for Machine_Lang in Machine_Lang_Enum'Range loop
	 
         case Machine_Lang is
	    when Project_Define =>
	       
	       if Object.Context.Project /= null and then Object.Context.Project.Project_Name /= null then
		  Load_Machine_Box(Object, Object.Context.Project.Proj_Library, Machine_Lang);	       	       
		  if Object.Gnose_Interface.Graph_set(Machine_Lang).Canvas/= null then
		     Clear_Canvas(Object.Gnose_Interface.Graph_set(Machine_Lang).Canvas);
		  end if;
		  if Object.Context.Project.Proj_Library.Unit_Index > 0 then	 	 
		     Canvas_Project_Constructor
		       (Object.Gnose_Interface.Graph_Set(Machine_Lang),
			Object.Context.Project.Proj_Library.Library_Unit,
			Object.Context.Project.Proj_Library.Unit_Index,
			False
		       );
		  end if;
	       end if;
	    when Ada_2012 =>
	       Text_Io.Put_Line("Reaload Ada 2012");
	       if Object.Context.projects_Params.With_ada then
		  
		  Text_Io.Put_Line("with Ada is setted");
		  Load_Machine_Box(Object, Object.Context.Project.Ada_Library, Machine_Lang);
		  
		  Text_Io.Put_Line("clear canvas");
		  Clear_Canvas(Object.Gnose_Interface.Graph_set(Machine_Lang).Canvas);
	       
		  if Object.Context.Project.Ada_Library.Unit_Index > 0 then	 	 
		     
		     Canvas_Project_Constructor
		       (Object.Gnose_Interface.Graph_Set(Machine_Lang),
			Object.Context.Project.Ada_Library.Library_Unit,
			Object.Context.Project.Ada_Library.Unit_Index,
			True
		       );
		  end if;
	       end if;
	    when Ada_Web_server =>
	       Text_Io.Put_Line("Reaload AWS");
	       if Object.Context.projects_Params.With_aws then
		  Load_Machine_Box(Object, Object.Context.Project.Aws_Library, Machine_Lang);
		  Clear_Canvas(Object.Gnose_Interface.Graph_set(Machine_Lang).Canvas);
		  
		  if Object.Context.Project.Aws_Library.Unit_Index > 0 then	 	 
		     
		     Canvas_Project_Constructor
		       (Object.Gnose_Interface.Graph_Set(Machine_Lang),
			Object.Context.Project.Aws_Library.Library_Unit,
		     Object.Context.Project.Aws_Library.Unit_Index,
			True
		       );
		  end if;
	       end if;
	    when Gtk_Ada =>
	       Text_Io.Put_Line("Reaload GtkAda");
	       if Object.Context.projects_Params.With_Gtk then

		  Load_Machine_Box(Object, Object.Context.Project.Gtk_Library, Machine_Lang);
		  Clear_Canvas(Object.Gnose_Interface.Graph_set(Machine_Lang).Canvas);
		  
		  if Object.Context.Project.Gtk_Library.Unit_Index > 0 then	 	 
		  
		     Canvas_Project_Constructor
		       (Object.Gnose_Interface.Graph_Set(Machine_Lang),
			Object.Context.Project.Gtk_Library.Library_Unit,
			Object.Context.Project.Gtk_Library.Unit_Index,
			True
		       );
		  end if;
	       end if;
	 end case;
	 
	 
      end loop;
      
      Show_All(Gtk_Window(Object.Gnose_interface));
   end Reload_Project;
   
   function Gnose_initialize 
     (Gnose_Context : access Gnose_Context_Record;
      Gnose_Params : access Gnose_Parameters_Type)
     
      return Gnose_Access is
      
      
      
      Gnostic : constant Object_Pointer := new Gnose_Record;
      
      Label : Gtk_Label;
      Error   : aliased GError := null;
   begin                  
      Text_Io.Put_Line("Going to Gtk_Window initialization...");      
      --  Initialize the colors
      
      for J in Color_Names'Range loop
         Colors (J) := Parse (Color_Names (J).all);
         --Alloc (Gtk.Widget.Get_Default_Colormap, Colors (J));
      end loop;
      
      --Text_Io.Put_Line("Colors set initialized.");

      
      declare
	 
	 
      begin
         --Text_Io.Put_Line("new gnose_interafce");
         Gnostic.Gnose_Interface := new Gnose_Interface_Record;
         --Text_Io.Put_Line("self Link gnose_interafce");
         Gnostic.Gnose_Interface.Gnostic := Gnostic.all'access;	 	 	 
         --Text_Io.Put_Line("gnostic context := gnose_context");
         Gnostic.Context := new gnose_context_record ' (Gnose_Context.All);      
         --Text_Io.Put_Line("new neural system set");
         Gnostic.System.Neural_Set := new Neural_Set_Array_Type(En..Fr);
         --Text_Io.Put_Line("Load network");
         for Human_Lang in Gnostic.System.Neural_Set'Range loop
            Load_network(Gnostic.System.Neural_Set.all, Human_Lang);
         end loop;
         Gnostic.System.Neural_Lang := Gnostic.Context.Gnose_Params.Human_Lang;
         --Text_Io.Put_Line("new Language_set");
         Gnostic.System.Language_Set := new Language_Set_Array_Type(Machine_Lang_Enum'range);
	 
         --Text_Io.Put_Line("Loading Project and Libraries");
         for Machine_Lang in Gnostic.System.Language_Set'Range loop
	    
            case Machine_Lang is
            when Project_Define =>		  
               Load_Language(Gnostic.System.Language_Set.all, Machine_Lang);
	    when Gtk_Ada =>
               if Gnostic.Context.projects_Params.With_Gtk then
                  Load_Language(Gnostic.System.Language_Set.all, Machine_Lang);
               end if;
            when Ada_Web_Server =>
               if Gnostic.Context.projects_Params.With_Aws then
                  Load_Language(Gnostic.System.Language_Set.all, Machine_Lang);
               end if;
		  
            when Ada_2012 =>
               if Gnostic.Context.projects_Params.With_Ada then
                  Load_Language(Gnostic.System.Language_Set.all, Machine_Lang);
               end if;
            end case;
         end loop;	 	 
         Text_Io.Put_Line("Machines initilaized...");
	 
         Gtk.Window.Initialize
           (Gtk_Window_record(Gnostic.Gnose_interface.all)'access, Gtk.Enums.Window_Toplevel);

	 
         Text_Io.Put_Line("Loading project...");
         Text_Io.New_Line;
         Agnose.Load_Project(Gnostic.Context.all, Ada_Path, Gtk_Path, Aws_Path, Pro_Path);
         Text_Io.New_Line;
         Text_Io.Put_Line("Project loaded.");
	 
         -------------------------------------------------------------------------------------
         -- Begin of Window construction :
	 
         Gtk_New(Gnostic.Gnose_Interface.System_Frame.Frame, "system");
         --Set_USize (Gnostic.Gnose_Interface.System_Frame.frame, 600, 200);
         Gtk_New_Vbox(Gnostic.Gnose_Interface.System_Frame.Box);
         Gtk_New(Gnostic.Gnose_Interface.System_Text_buffer);	 
         Gtk_New(Gnostic.Gnose_Interface.System_Text_View, Gnostic.Gnose_Interface.System_Text_Buffer);
         Set_Editable(Gnostic.Gnose_Interface.System_Text_View, False);
         Gtk_New(Gnostic.Gnose_Interface.System_Scroll);
         Add(Gnostic.Gnose_Interface.System_Scroll, Gnostic.Gnose_Interface.System_Text_View);	 
         Pack_Start(Gnostic.Gnose_Interface.System_Frame.Box, Gnostic.Gnose_Interface.System_Scroll);	 
         Add(Gnostic.Gnose_Interface.System_Frame.Frame, Gnostic.Gnose_Interface.System_Frame.Box);
         Text_Io.Put_Line("System frame");
         Gtk_New(Gnostic.Gnose_Interface.user_Frame.Frame, "user");
         --Set_USize (Gnostic.Gnose_Interface.User_Frame.frame, 600, 200);
         Gtk_New_Vbox(Gnostic.Gnose_Interface.user_Frame.Box);
         Gtk_New(Gnostic.Gnose_Interface.User_Text_buffer);	 	 
         Gtk_New(Gnostic.Gnose_Interface.User_Text_View, Gnostic.Gnose_Interface.User_Text_buffer);	 
         Set_Accepts_Tab(Gnostic.Gnose_Interface.User_Text_view, False);
         --Set_Editable(Gnostic.Gnose_Interface.User_Text_view, True);
         Gtk_New(Gnostic.Gnose_Interface.User_Scroll);
         Add(Gnostic.Gnose_Interface.User_Scroll, Gnostic.Gnose_Interface.User_Text_View);
         Pack_Start(Gnostic.Gnose_Interface.user_Frame.Box, Gnostic.Gnose_Interface.User_scroll);
         Add(Gnostic.Gnose_Interface.user_Frame.Frame, Gnostic.Gnose_Interface.user_Frame.Box);
	 
         Gnostic.Gnose_Interface.User_Handler := User_Cb_Handlers.Connect
           (Gnostic.Gnose_Interface.User_Text_Buffer, "changed",
            User_Cb_Handlers.To_Marshaller
              (On_change'Access),
            gnostic);
	 
	 
         Text_Io.Put_Line("user interfcae frame");
	 
	 
         Gtk_New(Gnostic.Gnose_Interface.Parmeters_Frame.Frame,"parameters");
	 
         Initialize_Parameters(Gnostic.Gnose_Interface.Parmeters_Frame.Frame,
                               Gnostic);
         Text_Io.Put_Line("parameters frame initialized");
	 
         Gtk_New(Gnostic.Gnose_Interface.Graph_Book);	 
         --Text_Io.Put_Line("new graph book");	 
	 
         Gtk_New_Vpaned(Gnostic.Gnose_Interface.Main_Pan);	 
         Gtk_New_Hpaned(Gnostic.Gnose_Interface.Bot_Main_Pan);	 
	 
         Pack1(Gnostic.Gnose_Interface.Main_Pan, Gnostic.Gnose_Interface.Graph_Book, False, False);	 
	 
         Text_Io.Put_Line("Machine initialization");
         for Machine_Lang in Machine_Lang_Enum'Range loop
	    
	    
            case Machine_Lang is
            when Project_Define =>		  
               
               if Gnostic.Context.Project.Proj_Library.Unit_Index > 0 then
                  --Text_Io.Put_Line("new project frame");
                  Gnostic.Gnose_Interface.Language_Set(Machine_Lang) := new Machine_Language_Frame_Type;		     
                  --Text_Io.Put_Line("Machine_init");
                  Machine_Init(Gnostic.Gnose_Interface.Language_Set(Machine_Lang).all, Machine_Lang);
                  --Text_Io.Put_Line("Load_Machine_box");
                  Load_Machine_Box(Gnostic, Gnostic.Context.Project.Proj_Library, Machine_Lang);		     
                  --Text_Io.Put_Line("Notebook set");
                  Notebook_Set(Gnostic.Gnose_Interface.Graph_Book, Gnostic.Gnose_Interface.Graph_Set, Gnostic.Context.Project.Proj_Library, Project_Define);  
                  --Text_Io.Put_Line("Project frames initialized.");
               else
                  
                  Gnostic.Gnose_Interface.Graph_Set(Machine_Lang) := new Canvas_Record_Type;		     
                  Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Canvas := new Image_Canvas_Record;

                  Initialize(Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Canvas);

                  Configure(Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Canvas);            
		     
                  Gnostic.Gnose_Interface.Language_Set(Machine_Lang) := new Machine_Language_Frame_Type;
		     
                  Machine_Init(Gnostic.Gnose_Interface.Language_Set(Machine_Lang).all, Machine_Lang);
		     
                  Gtk_New(Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Frame, Machine_Lang_Enum'Image(Machine_Lang));

                  Gtk_New(Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Scroll);

                  Add(Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Frame, Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Scroll);            

                  Gtk_New(Label, Machine_Lang_Enum'Image(Machine_Lang));      

                  Add(Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Scroll, Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Canvas);

                  Append_Page (Gnostic.Gnose_Interface.Graph_Book, Child => Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Frame, Tab_Label => Label);
                  Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Layout := Create_Pango_Layout (Gnostic.Gnose_Interface.Graph_set(Machine_Lang).Scroll);
                  --Text_Io.Put_Line("Project Canvas appened");
               end if;

            when Gtk_Ada =>
               if Gnostic.Context.Projects_Params.With_Gtk then
                  Gnostic.Gnose_Interface.Language_Set(Machine_Lang) := new Machine_Language_Frame_Type;
                  if Gnostic.Context.Project.Gtk_Library.Unit_Index > 0 then			
                     Machine_Init(Gnostic.Gnose_Interface.Language_Set(Machine_Lang).all, Machine_Lang);
                     Load_Machine_Box(Gnostic, Gnostic.Context.Project.Gtk_Library, Machine_Lang);
                     Notebook_Set(Gnostic.Gnose_Interface.Graph_Book, Gnostic.Gnose_Interface.Graph_Set, Gnostic.Context.Project.Gtk_Library, Gtk_Ada);
			
                  end if;
               else		     
                  Gnostic.Gnose_Interface.Graph_Set(Machine_Lang) := new Canvas_Record_Type;
                  Gnostic.Gnose_Interface.Language_Set(Machine_Lang) := new Machine_Language_Frame_Type;
                  Machine_Init(Gnostic.Gnose_Interface.Language_Set(Machine_Lang).all, Machine_Lang);
                  Gtk_New(Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Frame, Machine_Lang_Enum'Image(Machine_Lang));
                  Gtk_New(Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Scroll);
                  Add(Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Frame, Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Scroll);            
                  Gtk_New(Label, Machine_Lang_Enum'Image(Machine_Lang));      
                  Append_Page (Gnostic.Gnose_Interface.Graph_Book, Child => Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Frame, Tab_Label => Label);
               end if;
            when Ada_Web_Server =>
               if Gnostic.Context.Projects_Params.With_Aws then
                  Gnostic.Gnose_Interface.Language_Set(Machine_Lang) := new Machine_Language_Frame_Type;
                  if Gnostic.Context.Project.Aws_Library.Unit_Index > 0 then
			
                     Machine_Init(Gnostic.Gnose_Interface.Language_Set(Machine_Lang).all, Machine_Lang);
                     Load_Machine_Box(Gnostic, Gnostic.Context.Project.Aws_Library, Machine_Lang);
                     Notebook_Set(Gnostic.Gnose_Interface.Graph_Book, Gnostic.Gnose_Interface.Graph_Set, Gnostic.Context.Project.Aws_Library, Ada_Web_server);
			
                  end if;
               else
                  Gnostic.Gnose_Interface.Graph_Set(Machine_Lang) := new Canvas_Record_Type;
                  Gnostic.Gnose_Interface.Language_Set(Machine_Lang) := new Machine_Language_Frame_Type;
                  Machine_Init(Gnostic.Gnose_Interface.Language_Set(Machine_Lang).all, Machine_Lang);
                  Gtk_New(Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Frame, Machine_Lang_Enum'Image(Machine_Lang));
                  Gtk_New(Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Scroll);
                  Add(Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Frame, Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Scroll);            
                  Gtk_New(Label, Machine_Lang_Enum'Image(Machine_Lang));      
                  Append_Page (Gnostic.Gnose_Interface.Graph_Book, Child => Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Frame, Tab_Label => Label);
               end if;
		  
            when Ada_2012 =>
               if Gnostic.Context.Projects_Params.With_Ada then		     
                  Gnostic.Gnose_Interface.Language_Set(Machine_Lang) := new Machine_Language_Frame_Type;
                  if Gnostic.Context.Project.Ada_Library.Unit_Index > 0 then
			
                     Machine_Init(Gnostic.Gnose_Interface.Language_Set(Machine_Lang).all, Machine_Lang);
                     Load_Machine_Box(Gnostic, Gnostic.Context.Project.Ada_Library, Machine_Lang);
                     Notebook_Set(Gnostic.Gnose_Interface.Graph_Book, Gnostic.Gnose_Interface.Graph_Set, Gnostic.Context.Project.Ada_Library, Ada_2012);

                  end if;
               else
                  Gnostic.Gnose_Interface.Graph_Set(Machine_Lang) := new Canvas_Record_Type;
                  Gnostic.Gnose_Interface.Language_Set(Machine_Lang) := new Machine_Language_Frame_Type;
                  Machine_Init(Gnostic.Gnose_Interface.Language_Set(Machine_Lang).all, Machine_Lang);
                  Gtk_New(Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Frame, Machine_Lang_Enum'Image(Machine_Lang));
		     
                  Gtk_New(Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Scroll);
		     
                  Add(Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Frame, Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Scroll);            
		     
                  Gtk_New(Label, Machine_Lang_Enum'Image(Machine_Lang));      
		     
                  Append_Page (Gnostic.Gnose_Interface.Graph_Book, Child => Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Frame, Tab_Label => Label);
		     
               end if;
            end case;
         end loop;	 	 
	 
         --Text_Io.Put_Line("Graph book added.");
	 
	 
	 
         Pack2(Gnostic.Gnose_Interface.Main_Pan, Gnostic.Gnose_Interface.Bot_Main_Pan, False, False);
         Set_Position(Gnostic.Gnose_Interface.Bot_Main_Pan, 250);
	 
         Gtk_New_Hpaned(Gnostic.Gnose_Interface.Bot_Second_Pan);
         Pack1(Gnostic.Gnose_Interface.Bot_Main_Pan, Gnostic.Gnose_Interface.Bot_Second_Pan, False, False);
	 
	 
         Gtk_New_Vpaned(Gnostic.Gnose_Interface.First_Machines_Left_Pan);
	 
         Gtk_New_Vpaned(Gnostic.Gnose_Interface.Second_Machines_Left_Pan);
         Pack1(Gnostic.Gnose_Interface.First_Machines_Left_Pan, Gnostic.Gnose_Interface.Second_Machines_Left_Pan, False, False);
         --Text_Io.Put_Line("Language_set initialization....");
      	 if Gnostic.Gnose_Interface.Language_Set(Gtk_Ada) /= null then
            Pack1(Gnostic.Gnose_Interface.Second_Machines_Left_Pan, Gnostic.Gnose_Interface.Language_Set(Gtk_Ada).Frame);
         end if;
         --Text_Io.Put_Line("Gtkada added..");
         if Gnostic.Gnose_Interface.Language_Set(Ada_2012) /= null then
            Pack2(Gnostic.Gnose_Interface.Second_Machines_Left_Pan, Gnostic.Gnose_Interface.Language_Set(Ada_2012).Frame);	 
         end if;
         --Text_Io.Put_Line("Ada added..");

         if Gnostic.Gnose_Interface.Language_Set(Ada_Web_Server) /= null then
            Pack2(Gnostic.Gnose_Interface.First_Machines_Left_Pan, Gnostic.Gnose_Interface.Language_Set(Ada_Web_Server).Frame);
         end if;
         --Text_Io.Put_Line("AWS added..");

         --Text_Io.Put_Line("Language_set initialized;");

         Pack1(Gnostic.Gnose_Interface.Bot_Second_Pan, Gnostic.Gnose_Interface.First_Machines_Left_Pan, False, False);
         Set_Position(Gnostic.Gnose_Interface.Bot_second_Pan, 250);
	 
	 
         Gtk_New_Vpaned(Gnostic.Gnose_Interface.Human_Pan);
         Pack1(Gnostic.Gnose_Interface.Human_Pan, Gnostic.Gnose_Interface.System_Frame.Frame, False, False);
         Pack2(Gnostic.Gnose_Interface.Human_Pan, Gnostic.Gnose_Interface.User_Frame.frame, False, False);
         Set_Position(Gnostic.Gnose_Interface.Human_Pan, 250);
	 
         Pack2(Gnostic.Gnose_Interface.bot_Second_Pan, Gnostic.Gnose_Interface.Human_Pan, False, False);
	 
	 
         Gtk_New_Vpaned(Gnostic.Gnose_Interface.Project_Pan); 
         Pack2(Gnostic.Gnose_Interface.Bot_Main_Pan, Gnostic.Gnose_Interface.Project_Pan, False, False);
         Set_Position(Gnostic.Gnose_Interface.Bot_Main_Pan, 800);
         --Text_Io.Put_Line("Add project Frame");
         if Gnostic.Gnose_Interface.Language_Set(Project_Define) /= null then
            Pack1(Gnostic.Gnose_Interface.Project_Pan,Gnostic.Gnose_Interface.Language_Set(Project_Define).frame , False, False);	    
         end if;
	 
	 
         Pack2(Gnostic.Gnose_Interface.Project_Pan, Gnostic.Gnose_Interface.Parmeters_Frame.Frame , False, False);
	 
         ------------------------------------------------
         -- Initialize Main box :                      --
         ------------------------------------------------
         Gtk_New_Vbox(Gnostic.Gnose_Interface.Main_Vbox);
	 
         Gtk_New (Gnostic.Gnose_Interface.Actions, "Actions");
         Add_Actions (Gnostic.Gnose_Interface.Actions, Entries, To_Address(Gnostic));
         Gtk_New (Gnostic.Gnose_Interface.UI);
         Insert_Action_Group (Gnostic.Gnose_Interface.UI, Gnostic.Gnose_Interface.Actions, 0);
         Add_Accel_Group
           (Gtk_Window(Gnostic.Gnose_Interface), Get_Accel_Group (Gnostic.Gnose_Interface.UI));
	 
         if Add_UI_From_String (Gnostic.Gnose_Interface.UI, UI_Info, Error'Unchecked_Access) = 0 then
            Text_Io.Put_Line ("Building menus failed: " & Get_Message (Error));
            Error_Free (Error);
         end if;      
         Pack_Start (Gnostic.Gnose_Interface.MAin_Vbox, Get_Widget (Gnostic.Gnose_Interface.UI, "/MenuBar"), False, False, 5);
	 
	 
         Pack_start(Gnostic.Gnose_Interface.Main_Vbox, Gnostic.Gnose_Interface.Main_Pan, True, True, 0);
	 
         --Text_Io.Put_Line("Add main box to Gtk_Window");
	 
         Add(Gtk_Window_Record(Gnostic.Gnose_Interface.all)'access, Gnostic.Gnose_Interface.Main_Vbox);
     	 
	 
	 
	 
         Gtk.Window.Set_Focus(Gtk_Window_Record(Gnostic.Gnose_Interface.all)'Access, Gtk.Widget.Gtk_Widget(Gnostic.Gnose_Interface.User_Text_View));
	 
         Set_Tab_Pos(Gnostic.Gnose_Interface.Graph_Book, Pos_Left);
      	 
	 
         --Text_Io.Put_Line("-- End of Window construction.");
         -----------------------------------------------------------------------------------
	 
	 
         --Text_Io.Put_Line("Attach destroy Handler...");
	 
         Main_User_Cb_Handlers.Connect
           (Gtk_Window_Record(Gnostic.Gnose_Interface.all)'access, "destroy", 
            Main_User_Cb_Handlers.To_Marshaller
              (Main_Destroy'Access),
            Gnostic.all'access);
	 
         --Text_Io.Put_Line("Setting the default size...");
         Set_Default_Size(Gnostic.Gnose_interface, 1024, 720);
	 
         Gtk.Window.set_position(Gtk_Window(Gnostic.Gnose_Interface), Gtk.Enums.Win_Pos_Center);
         if Gnostic.context.Project.Project_Name /= null then
            Gtk.Window.Set_Title(Gtk_Window(Gnostic.Gnose_Interface), Gnostic.context.Project.Project_Name.all & " - " & To_String(Versions.Version));
         end if;
	 
	 
         Common_notebook_Cb.Connect
           (Gnostic.Gnose_Interface.Graph_book, "switch_page",
            Common_notebook_Cb.To_Marshaller (Page_Switched'Access),
            Gnostic,
            true);
	 
         for Machine_Lang in Machine_Lang_Enum'Range loop
            if Gnostic.Gnose_Interface.Graph_Set(Machine_Lang) /= null and then
              Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Canvas /= null then
               Realize(Gnostic.Gnose_Interface.Graph_Set(Machine_Lang).Canvas);
            end if;
         end loop;
	 
	 
         Calendar.Split(Clock, Start_Date.Year, Start_Date.Month, Start_Date.Day, Start_Date.Hours);
	 
         Gnostic.Process.Initialize
           (Clock, 
            Gnostic.Context.Neural_Params.Self_Wait, 
            Gnostic.Context.Neural_Params.Self_Wait);
	 
         Gnostic.Process.Run
           (Gnostic.Context.System_Params.Self_Programming,
            Gnostic.Context.System_Params.Self_Executed);      
	 
	 
         --Text_io.put_line("initialize Global layout.");
         Layout := Gnostic.Gnose_Interface.Graph_Set(Project_Define).Layout;
	 
         --Text_io.put_line("create make file");
	 
         if not Is_Regular_File("Makefile") then
            declare
               Project_Name : constant String := Random_Name(12);
            begin
               if Environment.Version_Reset = 0 then		  
                  declare
		     
                     Dialog : Gtk.Dialog.Gtk_Dialog;
                     Yes    : Gtk.Widget.Gtk_Widget;
                     No     : Gtk.Widget.Gtk_Widget;		     
                     Box    : Gtk_Vbox;
                     Label  : Gtk_Label;
                  begin
                     loop
                        Gtk_New(Label, Project_Name);
                        Gtk.Dialog.Gtk_New(Dialog, "Create project named :", Gtk_Window(Gnostic.Gnose_interface), Gtk.dialog.modal);
                        Set_Default_Size(Gtk_Window(Dialog), 150, 70);
                        Box := Get_Content_Area(Dialog);      
                        Pack_Start(Box, Label);
                        Yes := Gtk.Dialog.Add_Button(Dialog, "Yes", Gtk.Dialog.Gtk_Response_Yes);
                        No := Gtk.Dialog.Add_Button(Dialog, "No", Gtk.Dialog.Gtk_Response_No);         			
                        Show_All(Box);
                        case Gtk.Dialog.Run(Dialog) is
                        when Gtk.Dialog.Gtk_Response_Yes    =>             
			      
                           Makefile("Makefile");			      			      			      
                           if Gnostic.Context.System_Params.Self_Programming then
                              Initialize_Project_Window(Gnostic, Project_Name);			      
                           end if;
                           if Gnostic.Context.System_Params.Self_Executed then				 
                              Gnostic.Self_Execute_Timeout := Main_timeout.Timeout_Add(Guint(Gnostic.Context.Neural_Params.Self_Wait*1000.0), On_Self_Execution'Access, Gnostic.all'access);
                           end if;								
                           Gtk.Dialog.Destroy(Dialog);  	       
                           exit;
                        when Gtk.Dialog.Gtk_Response_No     =>
                           Makefile("Makefile");			      			      			      
                           Initialize_Project_Window(Gnostic, "");
                           if Gnostic.Context.System_Params.Self_Executed then				 
                              Gnostic.Self_Execute_Timeout := Main_timeout.Timeout_Add(Guint(Gnostic.Context.Neural_Params.Self_Wait*1000.0), On_Self_Execution'Access, Gnostic.all'access);
                           end if;				     
                           Gtk.Dialog.Destroy(Dialog);               
                           exit;
                        when others =>
                           Gtk.Dialog.Destroy(Dialog);	       
                           exit;
                        end case;
                     end loop;      
                  end;
               end if;
            end;	 
         elsif Gnostic.Context.System_Params.Self_Executed then
            Gnostic.Self_Execute_Timeout := Main_timeout.Timeout_Add(Guint(Gnostic.Context.Neural_Params.Self_Wait*1000.0), On_Self_Execution'Access, Gnostic.all'access);
         end if;
         --Text_Io.Put_Line("Show_all Window...");
         Gtk.Window.Show_All(Gtk_Window_Record(Gnostic.Gnose_Interface.all)'access);
	 
      end;

      return Gnostic.all'Access;
   end Gnose_Initialize;
   

   
end Lib.Graphs ;