← Back to team overview

kicad-developers team mailing list archive

Re: [PATCH] Add empty eeschema page layout for Eagle schematic import. Bug #1729722

 

Hi Russell,

Thank you very much for the patch. It works as expected and I would like
to merge it, but there are two things.

I have simplified the patch a bit (moved the empty layout to an existing
file, minor code formatting fixes), so please confirm you are ok with
committing it under your name.

Another question is about "there is a 0 length line to fool something
somewhere." comment for const char emptyLayout[]. Could you say
something more about it? I could not spot a 0 length line in the layout
description, so perhaps we can remove it to avoid confusion.

Regards,
Orson

On 02/03/2018 01:27 AM, Russell Oliver wrote:
> Attached is a patch that adds an empty layout using the same method as the
> SetDefaultLayout function, which is then called by the Eagle schematic
> plugin to leave only the imported frame visible.
> 
> https://bugs.launchpad.net/kicad/+bug/1729722
> 
> Kind Regards
> Russell
> 
> 
> 
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help   : https://help.launchpad.net/ListHelp
> 

From 63a3949a937ac96818fea19e45e8536a34a682ee Mon Sep 17 00:00:00 2001
From: Russell Oliver <russell.oliver@xxxxxxxxxxxxx>
Date: Fri, 2 Feb 2018 12:02:50 +1100
Subject: [PATCH] Add empty eeschema page layout for Eagle schematic import.

Fixes: lp:1729722
* https://bugs.launchpad.net/kicad/+bug/1729722
---
 .../page_layout_default_description.cpp            | 81 +++++++++++-----------
 common/page_layout/page_layout_reader.cpp          | 26 +++----
 eeschema/sch_eagle_plugin.cpp                      |  4 ++
 include/worksheet_shape_builder.h                  | 11 ++-
 4 files changed, 69 insertions(+), 53 deletions(-)

diff --git a/common/page_layout/page_layout_default_description.cpp b/common/page_layout/page_layout_default_description.cpp
index e019e6878..1f70406bc 100644
--- a/common/page_layout/page_layout_default_description.cpp
+++ b/common/page_layout/page_layout_default_description.cpp
@@ -115,8 +115,7 @@
  *
  */
 
-#include <worksheet.h>      // defaultPageLayout
-
+#include <worksheet.h>
 
 // height of the band reference grid  2.0 mm
 // worksheet frame reference text size 1.3 mm
@@ -124,41 +123,45 @@
 // default line width 0.15 mm
 // frame ref pitch 50 mm
 
-// export defaultPageLayout:
-extern const char   defaultPageLayout[];
-
 // Default page layout (sizes are in mm)
-const char          defaultPageLayout[] = "( page_layout\n"
-                                          "(setup (textsize 1.5 1.5) (linewidth 0.15) (textlinewidth 0.15)\n"
-                                          "(left_margin 10)(right_margin 10)(top_margin 10)(bottom_margin 10))\n"
-                                          "(rect (comment \"rect around the title block\") (linewidth 0.15) (start 110 34) (end 2 2) )\n"
-                                          "(rect (start 0 0 ltcorner) (end 0 0 rbcorner) (repeat 2) (incrx 2) (incry 2) )\n"
-                                          "(line (start 50 2 ltcorner) (end 50 0 ltcorner) (repeat 30) (incrx 50) )\n"
-                                          "(tbtext \"1\" (pos 25 1 ltcorner) (font (size 1.3 1.3))(repeat 100) (incrx 50) )\n"
-                                          "(line (start 50 2 lbcorner) (end 50 0 lbcorner) (repeat 30) (incrx 50) )\n"
-                                          "(tbtext \"1\" (pos 25 1 lbcorner) (font (size 1.3 1.3)) (repeat 100) (incrx 50) )\n"
-                                          "(line (start 0 50 ltcorner) (end 2 50 ltcorner) (repeat 30) (incry 50) )\n"
-                                          "(tbtext \"A\" (pos 1 25 ltcorner) (font (size 1.3 1.3)) (justify center)(repeat 100) (incry 50) )\n"
-                                          "(line (start 0 50 rtcorner) (end 2 50 rtcorner) (repeat 30) (incry 50) )\n"
-                                          "(tbtext \"A\" (pos 1 25 rtcorner) (font (size 1.3 1.3)) (justify center) (repeat 100) (incry 50) )\n"
-                                          "(tbtext \"Date: %D\" (pos 87 6.9) )\n"
-                                          "(line (start 110 5.5) (end 2 5.5) )\n"
-                                          "(tbtext \"%K\" (pos 109 4.1) (comment \"Kicad version\" ) )\n"
-                                          "(line (start 110 8.5) (end 2 8.5) )\n"
-                                          "(tbtext \"Rev: %R\" (pos 24 6.9)(font bold)(justify left) )\n"
-                                          "(tbtext \"Size: %Z\" (comment \"Paper format name\")(pos 109 6.9) )\n"
-                                          "(tbtext \"Id: %S/%N\" (comment \"Sheet id\")(pos 24 4.1) )\n"
-                                          "(line (start 110 12.5) (end 2 12.5) )\n"
-                                          "(tbtext \"Title: %T\" (pos 109 10.7)(font bold italic (size 2 2)) )\n"
-                                          "(tbtext \"File: %F\" (pos 109 14.3) )\n"
-                                          "(line (start 110 18.5) (end 2 18.5) )\n"
-                                          "(tbtext \"Sheet: %P\" (pos 109 17) )\n"
-                                          "(tbtext \"%Y\" (comment \"Company name\") (pos 109 20)(font bold) )\n"
-                                          "(tbtext \"%C0\" (comment \"Comment 0\") (pos 109 23) )\n"
-                                          "(tbtext \"%C1\" (comment \"Comment 1\") (pos 109 26) )\n"
-                                          "(tbtext \"%C2\" (comment \"Comment 2\") (pos 109 29) )\n"
-                                          "(tbtext \"%C3\" (comment \"Comment 3\") (pos 109 32) )\n"
-                                          "(line (start 90 8.5) (end 90 5.5) )\n"
-                                          "(line (start 26 8.5) (end 26 2) )\n"
-                                          ")\n"
-;
+extern const char defaultPageLayout[] =
+    "(page_layout\n"
+    "(setup (textsize 1.5 1.5) (linewidth 0.15) (textlinewidth 0.15)\n"
+    "(left_margin 10)(right_margin 10)(top_margin 10)(bottom_margin 10))\n"
+    "(rect (comment \"rect around the title block\") (linewidth 0.15) (start 110 34) (end 2 2) )\n"
+    "(rect (start 0 0 ltcorner) (end 0 0 rbcorner) (repeat 2) (incrx 2) (incry 2) )\n"
+    "(line (start 50 2 ltcorner) (end 50 0 ltcorner) (repeat 30) (incrx 50) )\n"
+    "(tbtext \"1\" (pos 25 1 ltcorner) (font (size 1.3 1.3))(repeat 100) (incrx 50) )\n"
+    "(line (start 50 2 lbcorner) (end 50 0 lbcorner) (repeat 30) (incrx 50) )\n"
+    "(tbtext \"1\" (pos 25 1 lbcorner) (font (size 1.3 1.3)) (repeat 100) (incrx 50) )\n"
+    "(line (start 0 50 ltcorner) (end 2 50 ltcorner) (repeat 30) (incry 50) )\n"
+    "(tbtext \"A\" (pos 1 25 ltcorner) (font (size 1.3 1.3)) (justify center)(repeat 100) (incry 50) )\n"
+    "(line (start 0 50 rtcorner) (end 2 50 rtcorner) (repeat 30) (incry 50) )\n"
+    "(tbtext \"A\" (pos 1 25 rtcorner) (font (size 1.3 1.3)) (justify center) (repeat 100) (incry 50) )\n"
+    "(tbtext \"Date: %D\" (pos 87 6.9) )\n"
+    "(line (start 110 5.5) (end 2 5.5) )\n"
+    "(tbtext \"%K\" (pos 109 4.1) (comment \"Kicad version\" ) )\n"
+    "(line (start 110 8.5) (end 2 8.5) )\n"
+    "(tbtext \"Rev: %R\" (pos 24 6.9)(font bold)(justify left) )\n"
+    "(tbtext \"Size: %Z\" (comment \"Paper format name\")(pos 109 6.9) )\n"
+    "(tbtext \"Id: %S/%N\" (comment \"Sheet id\")(pos 24 4.1) )\n"
+    "(line (start 110 12.5) (end 2 12.5) )\n"
+    "(tbtext \"Title: %T\" (pos 109 10.7)(font bold italic (size 2 2)) )\n"
+    "(tbtext \"File: %F\" (pos 109 14.3) )\n"
+    "(line (start 110 18.5) (end 2 18.5) )\n"
+    "(tbtext \"Sheet: %P\" (pos 109 17) )\n"
+    "(tbtext \"%Y\" (comment \"Company name\") (pos 109 20)(font bold) )\n"
+    "(tbtext \"%C0\" (comment \"Comment 0\") (pos 109 23) )\n"
+    "(tbtext \"%C1\" (comment \"Comment 1\") (pos 109 26) )\n"
+    "(tbtext \"%C2\" (comment \"Comment 2\") (pos 109 29) )\n"
+    "(tbtext \"%C3\" (comment \"Comment 3\") (pos 109 32) )\n"
+    "(line (start 90 8.5) (end 90 5.5) )\n"
+    "(line (start 26 8.5) (end 26 2) )\n"
+    ")\n";
+
+extern const char emptyPageLayout[] =
+    "(page_layout\n"
+    "(setup (textsize 1.5 1.5)(linewidth 0.15)(textlinewidth 0.15)\n"
+    "(left_margin 10)(right_margin 10)(top_margin 10)(bottom_margin 10))\n"
+    "(line (name segm1:Line) (start 0 0) (end 0 0))\n"
+    ")\n";
diff --git a/common/page_layout/page_layout_reader.cpp b/common/page_layout/page_layout_reader.cpp
index 1f197dfbb..ac9e540f7 100644
--- a/common/page_layout/page_layout_reader.cpp
+++ b/common/page_layout/page_layout_reader.cpp
@@ -760,24 +760,27 @@ extern const char defaultPageLayout[];
 
 void WORKSHEET_LAYOUT::SetDefaultLayout()
 {
-    ClearList();
-    PAGE_LAYOUT_READER_PARSER lp_parser( defaultPageLayout, wxT( "default page" ) );
+    SetPageLayout( defaultPageLayout, false, wxT( "default page" ) );
+}
 
-    try
-    {
-        lp_parser.Parse( this );
-    }
-    catch( const IO_ERROR& ioe )
-    {
-        wxLogMessage( ioe.What() );
-    }
+
+// emptyPageLayout is a "empty" page layout description
+// there is a 0 length line to fool something somewhere.
+// using the S expr.
+// see page_layout_empty_description.cpp
+extern const char emptyPageLayout[];
+
+void WORKSHEET_LAYOUT::SetEmptyLayout()
+{
+    SetPageLayout( emptyPageLayout, false, wxT( "empty page" ) );
 }
 
+
 /**
  * Populates the list from a S expr description stored in a string
  * @param aPageLayout = the S expr string
  */
-void WORKSHEET_LAYOUT::SetPageLayout( const char* aPageLayout, bool Append )
+void WORKSHEET_LAYOUT::SetPageLayout( const char* aPageLayout, bool Append, const wxString& aSource )
 {
     if( ! Append )
         ClearList();
@@ -859,4 +862,3 @@ void WORKSHEET_LAYOUT::SetPageLayout( const wxString& aFullFileName, bool Append
 
     delete[] buffer;
 }
-
diff --git a/eeschema/sch_eagle_plugin.cpp b/eeschema/sch_eagle_plugin.cpp
index 1278fa8e5..c3c224cde 100644
--- a/eeschema/sch_eagle_plugin.cpp
+++ b/eeschema/sch_eagle_plugin.cpp
@@ -30,6 +30,7 @@
 #include <sch_junction.h>
 #include <sch_sheet.h>
 #include <sch_edit_frame.h>
+#include <worksheet_shape_builder.h>
 #include <template_fieldnames.h>
 #include <wildcards_and_files_ext.h>
 #include <sch_screen.h>
@@ -374,6 +375,9 @@ SCH_SHEET* SCH_EAGLE_PLUGIN::Load( const wxString& aFileName, KIWAY* aKiway,
         m_rootSheet->SetScreen( screen );
     }
 
+    WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance();
+    pglayout.SetEmptyLayout();
+
     SYMBOL_LIB_TABLE* libTable = m_kiway->Prj().SchSymbolLibTable();
 
     wxCHECK_MSG( libTable, NULL, "Could not load symbol lib table." );
diff --git a/include/worksheet_shape_builder.h b/include/worksheet_shape_builder.h
index 4baa5df4b..6381e22a5 100644
--- a/include/worksheet_shape_builder.h
+++ b/include/worksheet_shape_builder.h
@@ -718,6 +718,11 @@ public:
     void SetDefaultLayout();
 
     /**
+     * Fills the list with an empty layout shape
+     */
+    void SetEmptyLayout();
+
+    /**
      * Populates the list with a custom layout, or
      * the default layout, if no custom layout available
      * @param aFullFileName = the custom page layout description file.
@@ -732,10 +737,12 @@ public:
     /**
      * Populates the list from a S expr description stored in a string
      * @param aPageLayout = the S expr string
-     * @param Append Do not delete old layout if true and append \a aPageLayout
+     * @param aAppend Do not delete old layout if true and append \a aPageLayout
      *               the existing one.
+       @param aSource is the layout source description.
      */
-    void SetPageLayout( const char* aPageLayout, bool Append = false );
+    void SetPageLayout( const char* aPageLayout, bool aAppend = false,
+            const wxString& aSource = wxT( "Sexpr_string" )  );
 
     /**
      * @return a short filename  from a full filename:
-- 
2.13.3

Attachment: signature.asc
Description: OpenPGP digital signature


Follow ups

References