summaryrefslogtreecommitdiff
path: root/pcbnew/pcad2kicadpcb_plugin
diff options
context:
space:
mode:
Diffstat (limited to 'pcbnew/pcad2kicadpcb_plugin')
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/CMakeLists.txt32
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/examples/files.txt7
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp553
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h104
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcad_plugin.cpp91
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcad_plugin.h60
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb.cpp937
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb.h92
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_arc.cpp193
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_arc.h61
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_callbacks.h64
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_component.cpp80
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_component.h87
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_copper_pour.cpp112
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_copper_pour.h54
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_cutout.cpp74
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_cutout.h53
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_keepout.cpp76
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_keepout.h52
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_line.cpp166
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_line.h62
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp640
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_module.h75
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_net.cpp104
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_net.h68
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_pad.cpp363
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_pad.h64
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_pad_shape.cpp142
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_pad_shape.h61
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_plane.cpp95
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_plane.h53
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_polygon.cpp253
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_polygon.h75
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp138
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_text.h59
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_via.cpp139
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_via.h54
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_via_shape.cpp88
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/pcb_via_shape.h52
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/s_expr_loader.cpp116
-rw-r--r--pcbnew/pcad2kicadpcb_plugin/s_expr_loader.h37
41 files changed, 5686 insertions, 0 deletions
diff --git a/pcbnew/pcad2kicadpcb_plugin/CMakeLists.txt b/pcbnew/pcad2kicadpcb_plugin/CMakeLists.txt
new file mode 100644
index 0000000..11e60de
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/CMakeLists.txt
@@ -0,0 +1,32 @@
+
+# Sources for the pcbnew PLUGIN called PCAD_PLUGIN
+
+# This CMakeLists.txt is included from pcbnew, so we are inheriting its include_directories(),
+# simply add the current source dir to inherited include_directories() for sources in here only.
+include_directories( . )
+
+
+set( PCAD2PCBNEW_SRCS
+ pcad2kicad_common.cpp
+ pcad_plugin.cpp
+ pcb.cpp
+ pcb_arc.cpp
+ pcb_component.cpp
+ pcb_copper_pour.cpp
+ pcb_cutout.cpp
+ pcb_keepout.cpp
+ pcb_line.cpp
+ pcb_module.cpp
+ pcb_net.cpp
+ pcb_pad.cpp
+ pcb_pad_shape.cpp
+ pcb_plane.cpp
+ pcb_polygon.cpp
+ pcb_text.cpp
+ pcb_via.cpp
+ pcb_via_shape.cpp
+ s_expr_loader.cpp
+ )
+
+add_library( pcad2kicadpcb STATIC ${PCAD2PCBNEW_SRCS} )
+add_dependencies( pcad2kicadpcb pcbcommon )
diff --git a/pcbnew/pcad2kicadpcb_plugin/examples/files.txt b/pcbnew/pcad2kicadpcb_plugin/examples/files.txt
new file mode 100644
index 0000000..ca06173
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/examples/files.txt
@@ -0,0 +1,7 @@
+
+Examples description
+====================
+A PCAD ASCII sample file can be downloaded from http://www.pcadbegin.webtm.ru
+(Provided by its author Andrey Manin <pcadbegin[at]rambler.ru>)
+
+http://www.pcadbegin.webtm.ru/schetchik.php?scach=1 (CK1202_V1.pcb)
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp
new file mode 100644
index 0000000..7ff4a60
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.cpp
@@ -0,0 +1,553 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2008, 2012 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcad2kicad_common.cpp
+ */
+
+#include <wx/wx.h>
+#include <wx/config.h>
+
+#include <common.h>
+#include <convert_to_biu.h>
+
+#include <pcad2kicad_common.h>
+
+namespace PCAD2KICAD {
+
+// PCAD stroke font average ratio of width to height
+const double TEXT_WIDTH_TO_HEIGHT = 0.79;
+
+wxString GetWord( wxString* aStr )
+{
+ wxString result = wxEmptyString;
+
+ *aStr = aStr->Trim( false );
+
+ if( aStr->Len() == 0 )
+ return result;
+
+ if( (*aStr)[0] == wxT( '"' ) )
+ {
+ result += (*aStr)[0];
+ *aStr = aStr->Mid( 1 ); // remove Frot apostrofe
+
+ while( aStr->Len() > 0 && (*aStr)[0] != wxT( '"' ) )
+ {
+ result += (*aStr)[0];
+ *aStr = aStr->Mid( 1 );
+ }
+
+ if( aStr->Len() > 0 && (*aStr)[0] == wxT( '"' ) )
+ {
+ result += (*aStr)[0];
+ *aStr = aStr->Mid( 1 ); // remove ending apostrophe
+ }
+ }
+ else
+ {
+ while( aStr->Len() > 0
+ && !( (*aStr)[0] == wxT( ' ' )
+ || (*aStr)[0] == wxT( '(' )
+ || (*aStr)[0] == wxT( ')' ) ) )
+ {
+ result += (*aStr)[0];
+ *aStr = aStr->Mid( 1 );
+ }
+ }
+
+ result.Trim( true );
+ result.Trim( false );
+
+ return result;
+}
+
+
+XNODE* FindPinMap( XNODE* aNode )
+{
+ XNODE* result, * lNode;
+
+ result = NULL;
+ lNode = FindNode( aNode, wxT( "attachedPattern" ) );
+
+ if( lNode )
+ result = FindNode( lNode, wxT( "padPinMap" ) );
+
+ return result;
+}
+
+
+double StrToDoublePrecisionUnits( wxString aStr, char aAxe, wxString aActualConversion )
+{
+ wxString ls;
+ double i;
+ char u;
+
+ ls = aStr;
+ ls.Trim( true );
+ ls.Trim( false );
+
+ if( ls.Len() > 0 )
+ {
+ u = ls[ls.Len() - 1];
+
+ while( ls.Len() > 0
+ && !( ls[ls.Len() - 1] == wxT( '.' )
+ || ls[ls.Len() - 1] == wxT( ',' )
+ || (ls[ls.Len() - 1] >= wxT( '0' ) && ls[ls.Len() - 1] <= wxT( '9' ) ) ) )
+ {
+ ls = ls.Left( ls.Len() - 1 );
+ }
+
+ while( ls.Len() > 0
+ && !( ls[0] == wxT( '-' )
+ || ls[0] == wxT( '+' )
+ || ls[0] == wxT( '.' )
+ || ls[0] == wxT( ',' )
+ || (ls[0] >= wxT( '0' ) && ls[0] <= wxT( '9' ) ) ) )
+ {
+ ls = ls.Mid( 1 );
+ }
+
+ if( u == wxT( 'm' ) )
+ {
+ ls.ToDouble( &i );
+#ifdef PCAD2KICAD_SCALE_SCH_TO_INCH_GRID
+ if( aActualConversion == wxT( "SCH" )
+ || aActualConversion == wxT( "SCHLIB" ) )
+ i = i * (0.0254 / 0.025);
+#endif
+ i = Millimeter2iu( i );
+ }
+ else
+ {
+ ls.ToDouble( &i );
+ i = Mils2iu( i );
+ }
+ }
+ else
+ i = 0.0;
+
+ if( ( aActualConversion == wxT( "PCB" ) || aActualConversion == wxT( "SCH" ) )
+ && aAxe == wxT( 'Y' ) )
+ return -i;
+ else
+ return i; // Y axe is mirrored compared to P-Cad
+}
+
+
+int StrToIntUnits( wxString aStr, char aAxe, wxString aActualConversion )
+{
+ return KiROUND( StrToDoublePrecisionUnits( aStr, aAxe, aActualConversion ) );
+}
+
+
+wxString GetAndCutWordWithMeasureUnits( wxString* aStr, wxString aDefaultMeasurementUnit )
+{
+ wxString result;
+
+ aStr->Trim( false );
+ result = wxEmptyString;
+
+ // value
+ while( aStr->Len() > 0 && (*aStr)[0] != wxT( ' ' ) )
+ {
+ result += (*aStr)[0];
+ *aStr = aStr->Mid( 1 );
+ }
+
+ aStr->Trim( false );
+
+ // if there is also measurement unit
+ while( aStr->Len() > 0
+ && ( ( (*aStr)[0] >= wxT( 'a' ) && (*aStr)[0] <= wxT( 'z' ) )
+ || ( (*aStr)[0] >= wxT( 'A' ) && (*aStr)[0] <= wxT( 'Z' ) ) ) )
+ {
+ result += (*aStr)[0];
+ *aStr = aStr->Mid( 1 );
+ }
+
+ // and if not, add default....
+ if( result.Len() > 0
+ && ( result[result.Len() - 1] == wxT( '.' )
+ || result[result.Len() - 1] == wxT( ',' )
+ || (result[result.Len() - 1] >= wxT( '0' )
+ && result[result.Len() - 1] <= wxT( '9' ) ) ) )
+ {
+ result += aDefaultMeasurementUnit;
+ }
+
+ return result;
+}
+
+
+int StrToInt1Units( wxString aStr )
+{
+ double num, precision = 10;
+
+ // TODO: Is the following commented string necessary?
+ // if (pos(',',s)>0) then DecimalSeparator:=',' else DecimalSeparator:='.';
+ aStr.ToDouble( &num );
+ return KiROUND( num * precision );
+}
+
+
+wxString ValidateName( wxString aName )
+{
+ aName.Replace( wxT( " " ), wxT( "_" ) );
+
+ return aName;
+}
+
+
+void SetWidth( wxString aStr,
+ wxString aDefaultMeasurementUnit,
+ int* aWidth,
+ wxString aActualConversion )
+{
+ *aWidth = StrToIntUnits( GetAndCutWordWithMeasureUnits( &aStr,
+ aDefaultMeasurementUnit ), wxT( ' ' ),
+ aActualConversion );
+}
+
+
+void SetHeight( wxString aStr,
+ wxString aDefaultMeasurementUnit,
+ int* aHeight,
+ wxString aActualConversion )
+{
+ *aHeight = StrToIntUnits( GetAndCutWordWithMeasureUnits( &aStr,
+ aDefaultMeasurementUnit ), wxT( ' ' ),
+ aActualConversion );
+}
+
+
+void SetPosition( wxString aStr,
+ wxString aDefaultMeasurementUnit,
+ int* aX,
+ int* aY,
+ wxString aActualConversion )
+{
+ *aX = StrToIntUnits( GetAndCutWordWithMeasureUnits( &aStr,
+ aDefaultMeasurementUnit ), wxT( 'X' ),
+ aActualConversion );
+ *aY = StrToIntUnits( GetAndCutWordWithMeasureUnits( &aStr,
+ aDefaultMeasurementUnit ), wxT( 'Y' ),
+ aActualConversion );
+}
+
+
+void SetDoublePrecisionPosition( wxString aStr,
+ wxString aDefaultMeasurementUnit,
+ double* aX,
+ double* aY,
+ wxString aActualConversion )
+{
+ *aX = StrToDoublePrecisionUnits( GetAndCutWordWithMeasureUnits( &aStr,
+ aDefaultMeasurementUnit ), wxT( 'X' ),
+ aActualConversion );
+ *aY = StrToDoublePrecisionUnits( GetAndCutWordWithMeasureUnits( &aStr,
+ aDefaultMeasurementUnit ), wxT( 'Y' ),
+ aActualConversion );
+}
+
+TTEXT_JUSTIFY GetJustifyIdentificator( wxString aJustify )
+{
+ TTEXT_JUSTIFY id;
+
+ if( aJustify == wxT( "LowerCenter" ) )
+ id = LowerCenter;
+ else if( aJustify == wxT( "LowerRight" ) )
+ id = LowerRight;
+ else if( aJustify == wxT( "UpperLeft" ) )
+ id = UpperLeft;
+ else if( aJustify == wxT( "UpperCenter" ) )
+ id = UpperCenter;
+ else if( aJustify == wxT( "UpperRight" ) )
+ id = UpperRight;
+ else if( aJustify == wxT( "Left" ) )
+ id = Left;
+ else if( aJustify == wxT( "Center" ) )
+ id = Center;
+ else if( aJustify == wxT( "Right" ) )
+ id = Right;
+ else
+ id = LowerLeft;
+
+ return id;
+}
+
+void SetTextParameters( XNODE* aNode,
+ TTEXTVALUE* aTextValue,
+ wxString aDefaultMeasurementUnit,
+ wxString aActualConversion )
+{
+ XNODE* tNode;
+ wxString str;
+
+ tNode = FindNode( aNode, wxT( "pt" ) );
+
+ if( tNode )
+ SetPosition( tNode->GetNodeContent(),
+ aDefaultMeasurementUnit,
+ &aTextValue->textPositionX,
+ &aTextValue->textPositionY,
+ aActualConversion );
+
+ tNode = FindNode( aNode, wxT( "rotation" ) );
+
+ if( tNode )
+ {
+ str = tNode->GetNodeContent();
+ str.Trim( false );
+ aTextValue->textRotation = StrToInt1Units( str );
+ }
+
+ str = FindNodeGetContent( aNode, wxT( "isVisible" ) );
+
+ if( str == wxT( "True" ) )
+ aTextValue->textIsVisible = 1;
+ else if( str == wxT( "False" ) )
+ aTextValue->textIsVisible = 0;
+
+ str = FindNodeGetContent( aNode, wxT( "justify" ) );
+ aTextValue->justify = GetJustifyIdentificator( str );
+
+ str = FindNodeGetContent( aNode, wxT( "isFlipped" ) );
+
+ if( str == wxT( "True" ) )
+ aTextValue->mirror = 1;
+
+ tNode = FindNode( aNode, wxT( "textStyleRef" ) );
+
+ if( tNode )
+ SetFontProperty( tNode, aTextValue, aDefaultMeasurementUnit, aActualConversion );
+}
+
+
+void SetFontProperty( XNODE* aNode,
+ TTEXTVALUE* aTextValue,
+ wxString aDefaultMeasurementUnit,
+ wxString aActualConversion )
+{
+ wxString n, propValue;
+
+ aNode->GetAttribute( wxT( "Name" ), &n );
+
+ while( aNode->GetName() != wxT( "www.lura.sk" ) )
+ aNode = aNode->GetParent();
+
+ aNode = FindNode( aNode, wxT( "library" ) );
+
+ if( aNode )
+ aNode = FindNode( aNode, wxT( "textStyleDef" ) );
+
+ if( aNode )
+ {
+ while( true )
+ {
+ aNode->GetAttribute( wxT( "Name" ), &propValue );
+ propValue.Trim( false );
+ propValue.Trim( true );
+
+ if( propValue == n )
+ break;
+
+ aNode = aNode->GetNext();
+ }
+
+ if( aNode )
+ {
+ aNode = FindNode( aNode, wxT( "font" ) );
+
+ if( aNode )
+ {
+ if( FindNode( aNode, wxT( "fontHeight" ) ) )
+ // // SetWidth(iNode.ChildNodes.FindNode('fontHeight').Text,
+ // // DefaultMeasurementUnit,tv.TextHeight);
+ // Fixed By Lubo, 02/2008
+ SetHeight( FindNode( aNode, wxT(
+ "fontHeight" ) )->GetNodeContent(),
+ aDefaultMeasurementUnit, &aTextValue->textHeight,
+ aActualConversion );
+
+ if( FindNode( aNode, wxT( "strokeWidth" ) ) )
+ SetWidth( FindNode( aNode, wxT(
+ "strokeWidth" ) )->GetNodeContent(),
+ aDefaultMeasurementUnit, &aTextValue->textstrokeWidth,
+ aActualConversion );
+ }
+ }
+ }
+}
+
+int CalculateTextLengthSize( TTEXTVALUE* aText )
+{
+ return KiROUND( (double) aText->text.Len() *
+ (double) aText->textHeight * TEXT_WIDTH_TO_HEIGHT );
+}
+
+void CorrectTextPosition( TTEXTVALUE* aValue )
+{
+ int cm = aValue->mirror ? -1 : 1;
+ // sizes of justify correction
+ int cl = KiROUND( (double) CalculateTextLengthSize( aValue ) / 2.0 );
+ int ch = KiROUND( (double) aValue->textHeight / 2.0 );
+
+ aValue->correctedPositionX = aValue->textPositionX;
+ aValue->correctedPositionY = aValue->textPositionY;
+
+ switch( aValue->textRotation )
+ {
+ case 0:
+ if( aValue->justify == LowerLeft ||
+ aValue->justify == Left ||
+ aValue->justify == UpperLeft )
+ aValue->correctedPositionX += cl * cm;
+ else if( aValue->justify == LowerRight ||
+ aValue->justify == Right ||
+ aValue->justify == UpperRight )
+ aValue->correctedPositionX -= cl * cm;
+
+ if( aValue->justify == LowerLeft ||
+ aValue->justify == LowerCenter ||
+ aValue->justify == LowerRight )
+ aValue->correctedPositionY -= ch;
+ else if( aValue->justify == UpperLeft ||
+ aValue->justify == UpperCenter ||
+ aValue->justify == UpperRight )
+ aValue->correctedPositionY += ch;
+ break;
+ case 900:
+ if( aValue->justify == LowerLeft ||
+ aValue->justify == LowerCenter ||
+ aValue->justify == LowerRight )
+ aValue->correctedPositionX -= ch * cm;
+ else if( aValue->justify == UpperLeft ||
+ aValue->justify == UpperCenter ||
+ aValue->justify == UpperRight )
+ aValue->correctedPositionX += ch * cm;
+
+ if( aValue->justify == LowerLeft ||
+ aValue->justify == Left ||
+ aValue->justify == UpperLeft )
+ aValue->correctedPositionY -= cl;
+ else if( aValue->justify == LowerRight ||
+ aValue->justify == Right ||
+ aValue->justify == UpperRight )
+ aValue->correctedPositionY += cl;
+ break;
+ case 1800:
+ if( aValue->justify == LowerLeft ||
+ aValue->justify == Left ||
+ aValue->justify == UpperLeft )
+ aValue->correctedPositionX -= cl * cm;
+ else if( aValue->justify == LowerRight ||
+ aValue->justify == Right ||
+ aValue->justify == UpperRight )
+ aValue->correctedPositionX += cl * cm;
+
+ if( aValue->justify == LowerLeft ||
+ aValue->justify == LowerCenter ||
+ aValue->justify == LowerRight )
+ aValue->correctedPositionY += ch;
+ else if( aValue->justify == UpperLeft ||
+ aValue->justify == UpperCenter ||
+ aValue->justify == UpperRight )
+ aValue->correctedPositionY -= ch;
+ break;
+ case 2700:
+ if( aValue->justify == LowerLeft ||
+ aValue->justify == LowerCenter ||
+ aValue->justify == LowerRight )
+ aValue->correctedPositionX += ch * cm;
+ else if( aValue->justify == UpperLeft ||
+ aValue->justify == UpperCenter ||
+ aValue->justify == UpperRight )
+ aValue->correctedPositionX -= ch * cm;
+
+ if( aValue->justify == LowerLeft ||
+ aValue->justify == Left ||
+ aValue->justify == UpperLeft )
+ aValue->correctedPositionY += cl;
+ else if( aValue->justify == LowerRight ||
+ aValue->justify == Right ||
+ aValue->justify == UpperRight )
+ aValue->correctedPositionY -= cl;
+ break;
+ default:
+ break;
+ }
+}
+
+
+XNODE* FindNode( XNODE* aChild, wxString aTag )
+{
+ aChild = aChild->GetChildren();
+
+ while( aChild )
+ {
+ if( aChild->GetName() == aTag )
+ return aChild;
+
+ aChild = aChild->GetNext();
+ }
+
+ return NULL;
+}
+
+wxString FindNodeGetContent( XNODE* aChild, wxString aTag )
+{
+ wxString str = wxEmptyString;
+
+ aChild = FindNode( aChild, aTag );
+
+ if( aChild )
+ {
+ str = aChild->GetNodeContent();
+ str.Trim( false );
+ str.Trim( true );
+ }
+
+ return str;
+}
+
+void InitTTextValue( TTEXTVALUE* aTextValue )
+{
+ aTextValue->text = wxEmptyString;
+ aTextValue->textPositionX = 0;
+ aTextValue->textPositionY = 0;
+ aTextValue->textRotation = 0;
+ aTextValue->textHeight = 0;
+ aTextValue->textstrokeWidth = 0;
+ aTextValue->textIsVisible = 0;
+ aTextValue->mirror = 0;
+ aTextValue->textUnit = 0;
+ aTextValue->correctedPositionX = 0;
+ aTextValue->correctedPositionY = 0;
+ aTextValue->justify = LowerLeft;
+}
+
+} // namespace PCAD2KICAD
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h
new file mode 100644
index 0000000..ce61cc2
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcad2kicad_common.h
@@ -0,0 +1,104 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2008, 2012 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcad2kicad_common.h
+ */
+
+#ifndef PCAD2KICAD_COMMON_H_
+#define PCAD2KICAD_COMMON_H_
+
+#include <wx/wx.h>
+#include <wx/xml/xml.h>
+#include <xnode.h>
+
+namespace PCAD2KICAD
+{
+
+#define PCAD2KICAD_SCALE_SCH_TO_INCH_GRID
+
+enum TTEXT_JUSTIFY
+{
+ LowerLeft,
+ LowerCenter,
+ LowerRight,
+ UpperLeft,
+ UpperCenter,
+ UpperRight,
+ Left,
+ Center,
+ Right
+};
+
+typedef struct _TTEXTVALUE
+{
+ wxString text;
+ int textPositionX, textPositionY,
+ textRotation, textHeight, textstrokeWidth;
+ int textIsVisible, mirror, textUnit;
+ int correctedPositionX, correctedPositionY;
+ TTEXT_JUSTIFY justify;
+} TTEXTVALUE;
+
+extern wxString GetWord( wxString* aStr );
+extern XNODE* FindPinMap( XNODE* aNode );
+extern int StrToIntUnits( wxString aStr, char aAxe, wxString aActualConversion );
+extern wxString GetAndCutWordWithMeasureUnits( wxString* aStr,
+ wxString aDefaultMeasurementUnit );
+extern int StrToInt1Units( wxString aStr );
+extern wxString ValidateName( wxString aName );
+extern void SetWidth( wxString aStr,
+ wxString aDefaultMeasurementUnit,
+ int* aWidth,
+ wxString aActualConversion );
+extern void SetPosition( wxString aStr,
+ wxString aDefaultMeasurementUnit,
+ int* aX,
+ int* aY,
+ wxString aActualConversion );
+extern void SetDoublePrecisionPosition( wxString aStr,
+ wxString aDefaultMeasurementUnit,
+ double* aX,
+ double* aY,
+ wxString aActualConversion );
+extern TTEXT_JUSTIFY GetJustifyIdentificator( wxString aJustify );
+extern void SetTextParameters( XNODE* aNode,
+ TTEXTVALUE* aTextValue,
+ wxString aDefaultMeasurementUnit,
+ wxString aActualConversion );
+extern void SetFontProperty( XNODE* aNode,
+ TTEXTVALUE* aTextValue,
+ wxString aDefaultMeasurementUnit,
+ wxString aActualConversion );
+extern int CalculateTextLengthSize( TTEXTVALUE* aText );
+extern void CorrectTextPosition( TTEXTVALUE* aValue );
+
+extern XNODE* FindNode( XNODE* aChild, wxString aTag );
+extern wxString FindNodeGetContent( XNODE* aChild, wxString aTag );
+extern void InitTTextValue( TTEXTVALUE* aTextValue );
+
+} // namespace PCAD2KICAD
+
+#endif // PCAD2KICAD_COMMON_H_
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcad_plugin.cpp b/pcbnew/pcad2kicadpcb_plugin/pcad_plugin.cpp
new file mode 100644
index 0000000..0c7c75c
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcad_plugin.cpp
@@ -0,0 +1,91 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2012 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcad_plugin.cpp
+ * @brief Pcbnew PLUGIN for P-Cad 200x ASCII *.pcb format.
+ */
+
+#include <errno.h>
+
+#include <wx/string.h>
+#include <wx/filename.h>
+#include <wx/xml/xml.h>
+
+#include <pcad_plugin.h>
+#include <s_expr_loader.h>
+#include <pcb.h>
+
+#include <common.h>
+#include <macros.h>
+#include <fctsys.h>
+
+using namespace PCAD2KICAD;
+
+PCAD_PLUGIN::PCAD_PLUGIN()
+{
+ m_board = NULL;
+ m_props = NULL;
+}
+
+
+PCAD_PLUGIN::~PCAD_PLUGIN()
+{
+}
+
+
+const wxString PCAD_PLUGIN::PluginName() const
+{
+ return wxT( "P-Cad" );
+}
+
+
+const wxString PCAD_PLUGIN::GetFileExtension() const
+{
+ return wxT( "pcb" );
+}
+
+
+BOARD* PCAD_PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe, const PROPERTIES* aProperties )
+{
+ wxXmlDocument xmlDoc;
+
+ m_props = aProperties;
+
+ m_board = aAppendToMe ? aAppendToMe : new BOARD();
+
+ // Give the filename to the board if it's new
+ if( !aAppendToMe )
+ m_board->SetFileName( aFileName );
+
+ PCB pcb( m_board );
+
+ LOCALE_IO toggle; // toggles on, then off, the C locale.
+
+ LoadInputFile( aFileName, &xmlDoc );
+ pcb.Parse( NULL, &xmlDoc, wxT( "PCB" ) );
+ pcb.AddToBoard();
+
+ return m_board;
+}
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcad_plugin.h b/pcbnew/pcad2kicadpcb_plugin/pcad_plugin.h
new file mode 100644
index 0000000..45ecbd9
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcad_plugin.h
@@ -0,0 +1,60 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2012 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcad_plugin.h
+ * @brief Pcbnew PLUGIN for P-Cad 200x ASCII *.pcb format.
+ */
+
+#ifndef PCAD_PLUGIN_H_
+#define PCAD_PLUGIN_H_
+
+
+#include <io_mgr.h>
+
+class PCAD_PLUGIN : public PLUGIN
+{
+public:
+
+ // -----<PUBLIC PLUGIN API>--------------------------------------------------
+
+ const wxString PluginName() const;
+
+ BOARD* Load( const wxString& aFileName,
+ BOARD* aAppendToMe,
+ const PROPERTIES* aProperties = NULL );
+
+ const wxString GetFileExtension() const;
+
+ // -----</PUBLIC PLUGIN API>-------------------------------------------------
+
+ PCAD_PLUGIN();
+ ~PCAD_PLUGIN();
+
+private:
+ const PROPERTIES* m_props;
+ BOARD* m_board;
+};
+
+#endif // PCAD_PLUGIN_H_
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb.cpp
new file mode 100644
index 0000000..feedb83
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb.cpp
@@ -0,0 +1,937 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb.cpp
+ */
+
+#include <wx/wx.h>
+#include <wx/config.h>
+
+#include <common.h>
+
+#include <pcb.h>
+#include <pcb_arc.h>
+#include <pcb_copper_pour.h>
+#include <pcb_cutout.h>
+#include <pcb_keepout.h>
+#include <pcb_line.h>
+#include <pcb_module.h>
+#include <pcb_pad_shape.h>
+#include <pcb_via_shape.h>
+#include <pcb_pad.h>
+#include <pcb_text.h>
+#include <pcb_via.h>
+#include <s_expr_loader.h>
+
+namespace PCAD2KICAD {
+
+LAYER_ID PCB::GetKiCadLayer( int aPCadLayer )
+{
+ wxASSERT( aPCadLayer >= 0 && aPCadLayer < MAX_PCAD_LAYER_QTY );
+ return m_layersMap[aPCadLayer].KiCadLayer;
+}
+
+LAYER_TYPE_T PCB::GetLayerType( int aPCadLayer )
+{
+ wxASSERT( aPCadLayer >= 0 && aPCadLayer < MAX_PCAD_LAYER_QTY );
+ return m_layersMap[aPCadLayer].layerType;
+}
+
+wxString PCB::GetLayerNetNameRef( int aPCadLayer )
+{
+ wxASSERT( aPCadLayer >= 0 && aPCadLayer < MAX_PCAD_LAYER_QTY );
+ return m_layersMap[aPCadLayer].netNameRef;
+}
+
+PCB::PCB( BOARD* aBoard ) : PCB_MODULE( this, aBoard )
+{
+ int i;
+
+ m_defaultMeasurementUnit = wxT( "mil" );
+
+ for( i = 0; i < MAX_PCAD_LAYER_QTY; i++ )
+ {
+ m_layersMap[i].KiCadLayer = F_Mask; // default
+ m_layersMap[i].layerType = LAYER_TYPE_NONSIGNAL; // default
+ m_layersMap[i].netNameRef = wxT( "" ); // default
+ }
+
+ m_sizeX = 0;
+ m_sizeY = 0;
+
+ m_layersMap[1].KiCadLayer = F_Cu;
+ m_layersMap[1].layerType = LAYER_TYPE_SIGNAL;
+
+ m_layersMap[2].KiCadLayer = B_Cu;
+ m_layersMap[2].layerType = LAYER_TYPE_SIGNAL;
+
+ m_layersMap[3].KiCadLayer = Eco2_User;
+ m_layersMap[6].KiCadLayer = F_SilkS;
+ m_layersMap[7].KiCadLayer = B_SilkS;
+ m_timestamp_cnt = 0x10000000;
+}
+
+
+PCB::~PCB()
+{
+ int i;
+
+ for( i = 0; i < (int) m_pcbComponents.GetCount(); i++ )
+ {
+ delete m_pcbComponents[i];
+ }
+
+ for( i = 0; i < (int) m_pcbNetlist.GetCount(); i++ )
+ {
+ delete m_pcbNetlist[i];
+ }
+}
+
+
+int PCB::GetNewTimestamp()
+{
+ return m_timestamp_cnt++;
+}
+
+int PCB::GetNetCode( wxString aNetName )
+{
+ PCB_NET* net;
+
+ for( int i = 0; i < (int) m_pcbNetlist.GetCount(); i++ )
+ {
+ net = m_pcbNetlist[i];
+
+ if( net->m_name == aNetName )
+ {
+ return net->m_netCode;
+ }
+ }
+
+ return 0;
+}
+
+XNODE* PCB::FindCompDefName( XNODE* aNode, wxString aName )
+{
+ XNODE* result = NULL, * lNode;
+ wxString propValue;
+
+ lNode = FindNode( aNode, wxT( "compDef" ) );
+
+ while( lNode )
+ {
+ if( lNode->GetName() == wxT( "compDef" ) )
+ {
+ lNode->GetAttribute( wxT( "Name" ), &propValue );
+
+ if( propValue == aName )
+ {
+ result = lNode;
+ lNode = NULL;
+ }
+ }
+
+ if( lNode )
+ lNode = lNode->GetNext();
+ }
+
+ return result;
+}
+
+
+void PCB::SetTextProperty( XNODE* aNode, TTEXTVALUE* aTextValue,
+ wxString aPatGraphRefName, wxString aXmlName,
+ wxString aActualConversion )
+{
+ XNODE* tNode, * t1Node;
+ wxString n, nnew, pn, propValue, str;
+
+ // aNode is pattern now
+ tNode = aNode;
+ t1Node = aNode;
+ n = aXmlName;
+
+ // new file format version
+ if( FindNode( tNode, wxT( "patternGraphicsNameRef" ) ) )
+ {
+ FindNode( tNode,
+ wxT( "patternGraphicsNameRef" ) )->GetAttribute( wxT( "Name" ),
+ &pn );
+ pn.Trim( false );
+ pn.Trim( true );
+ tNode = FindNode( tNode, wxT( "patternGraphicsRef" ) );
+
+ while( tNode )
+ {
+ if( tNode->GetName() == wxT( "patternGraphicsRef" ) )
+ {
+ if( FindNode( tNode, wxT( "patternGraphicsNameRef" ) ) )
+ {
+ FindNode( tNode,
+ wxT( "patternGraphicsNameRef" ) )->GetAttribute( wxT( "Name" ),
+ &propValue );
+
+ if( propValue == pn )
+ {
+ t1Node = tNode; // find correct section with same name.
+ str = aTextValue->text;
+ str.Trim( false );
+ str.Trim( true );
+ nnew = n; // new file version
+ n = n + wxT( ' ' ) + str; // old file version
+ tNode = NULL;
+ }
+ }
+ }
+
+ if( tNode )
+ tNode = tNode->GetNext();
+ }
+ }
+
+ // old version and compatibile fr both from this point
+ tNode = FindNode( t1Node, wxT( "attr" ) );
+
+ while( tNode )
+ {
+ tNode->GetAttribute( wxT( "Name" ), &propValue );
+ propValue.Trim( false );
+ propValue.Trim( true );
+
+ if( propValue == n || propValue == nnew )
+ break;
+
+ tNode = tNode->GetNext();
+ }
+
+ if( tNode )
+ SetTextParameters( tNode, aTextValue, m_defaultMeasurementUnit, aActualConversion );
+}
+
+
+void PCB::DoPCBComponents( XNODE* aNode,
+ wxXmlDocument* aXmlDoc,
+ wxString aActualConversion,
+ wxStatusBar* aStatusBar )
+{
+ XNODE* lNode, * tNode, * mNode;
+ PCB_MODULE* mc;
+ PCB_PAD* pad;
+ PCB_VIA* via;
+ PCB_KEEPOUT* keepOut;
+ wxString cn, str, propValue;
+
+ lNode = aNode->GetChildren();
+
+ while( lNode )
+ {
+ mc = NULL;
+
+ if( lNode->GetName() == wxT( "pattern" ) )
+ {
+ FindNode( lNode, wxT( "patternRef" ) )->GetAttribute( wxT( "Name" ),
+ &cn );
+ cn = ValidateName( cn );
+ tNode = FindNode( (XNODE *)aXmlDoc->GetRoot(), wxT( "library" ) );
+
+ if( tNode && cn.Len() > 0 )
+ {
+ tNode = FindModulePatternDefName( tNode, cn );
+
+ if( tNode )
+ {
+ mc = new PCB_MODULE( this, m_board );
+
+ mNode = FindNode( lNode, wxT( "patternGraphicsNameRef" ) );
+ if( mNode )
+ mNode->GetAttribute( wxT( "Name" ), &mc->m_patGraphRefName );
+
+ mc->Parse( tNode, aStatusBar, m_defaultMeasurementUnit, aActualConversion );
+ }
+ }
+
+ if( mc )
+ {
+ mc->m_compRef = cn; // default - in new version of file it is updated later....
+ tNode = FindNode( lNode, wxT( "refDesRef" ) );
+
+ if( tNode )
+ {
+ tNode->GetAttribute( wxT( "Name" ), &mc->m_name.text );
+ SetTextProperty( lNode, &mc->m_name, mc->m_patGraphRefName, wxT(
+ "RefDes" ), aActualConversion );
+ SetTextProperty( lNode, &mc->m_value, mc->m_patGraphRefName, wxT(
+ "Value" ), aActualConversion );
+ }
+
+ tNode = FindNode( lNode, wxT( "pt" ) );
+
+ if( tNode )
+ SetPosition( tNode->GetNodeContent(),
+ m_defaultMeasurementUnit,
+ &mc->m_positionX,
+ &mc->m_positionY,
+ aActualConversion );
+
+ tNode = FindNode( lNode, wxT( "rotation" ) );
+
+ if( tNode )
+ {
+ str = tNode->GetNodeContent();
+ str.Trim( false );
+ mc->m_rotation = StrToInt1Units( str );
+ }
+
+ str = FindNodeGetContent( lNode, wxT( "isFlipped" ) );
+
+ if( str == wxT( "True" ) )
+ mc->m_mirror = 1;
+
+ tNode = aNode;
+
+ while( tNode->GetName() != wxT( "www.lura.sk" ) )
+ tNode = tNode->GetParent();
+
+ tNode = FindNode( tNode, wxT( "netlist" ) );
+
+ if( tNode )
+ {
+ tNode = FindNode( tNode, wxT( "compInst" ) );
+
+ while( tNode )
+ {
+ tNode->GetAttribute( wxT( "Name" ), &propValue );
+
+ if( propValue == mc->m_name.text )
+ {
+ if( FindNode( tNode, wxT( "compValue" ) ) )
+ {
+ FindNode( tNode,
+ wxT( "compValue" ) )->GetAttribute( wxT( "Name" ),
+ &mc->m_value.text );
+ mc->m_value.text.Trim( false );
+ mc->m_value.text.Trim( true );
+ }
+
+ if( FindNode( tNode, wxT( "compRef" ) ) )
+ {
+ FindNode( tNode,
+ wxT( "compRef" ) )->GetAttribute( wxT( "Name" ),
+ &mc->m_compRef );
+ mc->m_compRef.Trim( false );
+ mc->m_compRef.Trim( true );
+ }
+
+ tNode = NULL;
+ }
+ else
+ tNode = tNode->GetNext();
+ }
+ }
+
+ // map pins
+ tNode = FindNode( (XNODE *)aXmlDoc->GetRoot(), wxT( "library" ) );
+ tNode = FindCompDefName( tNode, mc->m_compRef );
+
+ if( tNode )
+ {
+ tNode = FindPinMap( tNode );
+
+ if( tNode )
+ {
+ mNode = tNode->GetChildren();
+
+ while( mNode )
+ {
+ if( mNode->GetName() == wxT( "padNum" ) )
+ {
+ str = mNode->GetNodeContent();
+ mNode = mNode->GetNext();
+
+ if( !mNode )
+ break;
+
+ mNode->GetAttribute( wxT( "Name" ), &propValue );
+ mc->SetPadName( str, propValue );
+ mNode = mNode->GetNext();
+ }
+ else
+ {
+ mNode = mNode->GetNext();
+
+ if( !mNode )
+ break;
+
+ mNode = mNode->GetNext();
+ }
+ }
+ }
+ }
+
+ m_pcbComponents.Add( mc );
+ }
+ }
+ else if( lNode->GetName() == wxT( "pad" ) )
+ {
+ pad = new PCB_PAD( this, m_board );
+ pad->Parse( lNode, m_defaultMeasurementUnit, aActualConversion );
+ m_pcbComponents.Add( pad );
+ }
+ else if( lNode->GetName() == wxT( "via" ) )
+ {
+ via = new PCB_VIA( this, m_board );
+ via->Parse( lNode, m_defaultMeasurementUnit, aActualConversion );
+ m_pcbComponents.Add( via );
+ }
+ else if( lNode->GetName() == wxT( "polyKeepOut" ) )
+ {
+ keepOut = new PCB_KEEPOUT( m_callbacks, m_board, 0 );
+
+ if( keepOut->Parse( lNode, m_defaultMeasurementUnit, aActualConversion ) )
+ m_pcbComponents.Add( keepOut );
+ else
+ delete keepOut;
+ }
+
+ lNode = lNode->GetNext();
+ }
+}
+
+
+void PCB::ConnectPinToNet( wxString aCompRef, wxString aPinRef, wxString aNetName )
+{
+ PCB_MODULE* module;
+ PCB_PAD* cp;
+ int i, j;
+
+ for( i = 0; i < (int) m_pcbComponents.GetCount(); i++ )
+ {
+ module = (PCB_MODULE*) m_pcbComponents[i];
+
+ if( module->m_objType == wxT( 'M' ) && module->m_name.text == aCompRef )
+ {
+ for( j = 0; j < (int) module->m_moduleObjects.GetCount(); j++ )
+ {
+ if( module->m_moduleObjects[j]->m_objType == wxT( 'P' ) )
+ {
+ cp = (PCB_PAD*) module->m_moduleObjects[j];
+
+ if( cp->m_name.text == aPinRef )
+ cp->m_net = aNetName;
+ }
+ }
+ }
+ }
+}
+
+
+int PCB::FindLayer( wxString aLayerName )
+{
+ for( LAYER_NUM i = 0; i < (int)m_layersStackup.GetCount(); ++i )
+ {
+ if( m_layersStackup[i] == aLayerName )
+ return i;
+ }
+
+ return -1;
+}
+
+
+/* KiCad layers
+ * 0 Copper layer
+ * 1 to 14 Inner layers
+ * 15 Component layer
+ * 16 Copper side adhesive layer Technical layers
+ * 17 Component side adhesive layer
+ * 18 Copper side Solder paste layer
+ * 19 Component Solder paste layer
+ * 20 Copper side Silk screen layer
+ * 21 Component Silk screen layer
+ * 22 Copper side Solder mask layer
+ * 23 Component Solder mask layer
+ * 24 Draw layer (Used for general drawings)
+ * 25 Comment layer (Other layer used for general drawings)
+ * 26 ECO1 layer (Other layer used for general drawings) // BUG
+ * 26 ECO2 layer (Other layer used for general drawings) // BUG 27
+ * 27 Edge layer. Items on Edge layer are seen on all layers // BUG 28
+ */
+void PCB::MapLayer( XNODE* aNode )
+{
+ wxString lName, layerType;
+ LAYER_ID KiCadLayer;
+ long num = 0;
+
+ aNode->GetAttribute( wxT( "Name" ), &lName );
+ lName = lName.MakeUpper();
+
+ if( lName == wxT( "TOP ASSY" ) )
+ KiCadLayer = Cmts_User;
+ else if( lName == wxT( "TOP SILK" ) )
+ KiCadLayer = F_SilkS;
+ else if( lName == wxT( "TOP PASTE" ) )
+ KiCadLayer = F_Paste;
+ else if( lName == wxT( "TOP MASK" ) )
+ KiCadLayer = F_Mask;
+ else if( lName == wxT( "TOP" ) )
+ KiCadLayer = F_Cu;
+ else if( lName == wxT( "BOTTOM" ) )
+ KiCadLayer = B_Cu;
+ else if( lName == wxT( "BOT MASK" ) )
+ KiCadLayer = B_Mask;
+ else if( lName == wxT( "BOT PASTE" ) )
+ KiCadLayer = B_Paste;
+ else if( lName == wxT( "BOT SILK" ) )
+ KiCadLayer = B_SilkS;
+ else if( lName == wxT( "BOT ASSY" ) )
+ KiCadLayer = Dwgs_User;
+ else if( lName == wxT( "BOARD" ) )
+ KiCadLayer = Edge_Cuts;
+ else
+ {
+ int layernum = FindLayer( lName );
+
+ if( layernum == -1 )
+ KiCadLayer = Dwgs_User; // default
+ else
+#if 0 // was:
+ KiCadLayer = FIRST_COPPER_LAYER + m_layersStackup.GetCount() - 1 - layernum;
+#else
+ KiCadLayer = ToLAYER_ID( layernum );
+#endif
+ }
+
+ if( FindNode( aNode, wxT( "layerNum" ) ) )
+ FindNode( aNode, wxT( "layerNum" ) )->GetNodeContent().ToLong( &num );
+
+ if( num < 0 || num >= MAX_PCAD_LAYER_QTY )
+ THROW_IO_ERROR( wxString::Format( wxT( "layerNum = %ld is out of range" ), num ) );
+
+ m_layersMap[(int) num].KiCadLayer = KiCadLayer;
+
+ if( FindNode( aNode, wxT( "layerType" ) ) )
+ {
+ layerType = FindNode( aNode, wxT( "layerType" ) )->GetNodeContent().Trim( false );
+
+ if( layerType == wxT( "NonSignal" ) )
+ m_layersMap[(int) num].layerType = LAYER_TYPE_NONSIGNAL;
+ if( layerType == wxT( "Signal" ) )
+ m_layersMap[(int) num].layerType = LAYER_TYPE_SIGNAL;
+ if( layerType == wxT( "Plane" ) )
+ m_layersMap[(int) num].layerType = LAYER_TYPE_PLANE;
+ }
+
+ if( FindNode( aNode, wxT( "netNameRef" ) ) )
+ {
+ FindNode( aNode, wxT( "netNameRef" ) )->GetAttribute( wxT( "Name" ),
+ &m_layersMap[(int) num].netNameRef );
+ }
+}
+
+int PCB::FindOutlinePoint( VERTICES_ARRAY* aOutline, wxRealPoint aPoint )
+{
+ int i;
+
+ for( i = 0; i < (int) aOutline->GetCount(); i++ )
+ if( *((*aOutline)[i]) == aPoint )
+ return i;
+
+ return -1;
+}
+
+/*int cmpFunc( wxRealPoint **first, wxRealPoint **second )
+{
+ return sqrt( pow( (double) aPointA.x - (double) aPointB.x, 2 ) +
+ pow( (double) aPointA.y - (double) aPointB.y, 2 ) );
+
+ return 0;
+}*/
+double PCB::GetDistance( wxRealPoint* aPoint1, wxRealPoint* aPoint2 )
+{
+ return sqrt( ( aPoint1->x - aPoint2->x ) *
+ ( aPoint1->x - aPoint2->x ) +
+ ( aPoint1->y - aPoint2->y ) *
+ ( aPoint1->y - aPoint2->y ) );
+}
+
+void PCB::GetBoardOutline( wxXmlDocument* aXmlDoc, wxString aActualConversion )
+{
+ XNODE* iNode, *lNode, *pNode;
+ long PCadLayer = 0;
+ int x, y, i, j, targetInd;
+ wxRealPoint* xchgPoint;
+ double minDistance, distance;
+
+ iNode = FindNode( (XNODE *)aXmlDoc->GetRoot(), wxT( "pcbDesign" ) );
+
+ if( iNode )
+ {
+ // COMPONENTS AND OBJECTS
+ iNode = iNode->GetChildren();
+
+ while( iNode )
+ {
+ // objects
+ if( iNode->GetName() == wxT( "layerContents" ) )
+ {
+ if( FindNode( iNode, wxT( "layerNumRef" ) ) )
+ FindNode( iNode, wxT( "layerNumRef" ) )->GetNodeContent().ToLong( &PCadLayer );
+
+ if( GetKiCadLayer( PCadLayer ) == Edge_Cuts )
+ {
+ lNode = iNode->GetChildren();
+ while( lNode )
+ {
+ if( lNode->GetName() == wxT( "line" ) )
+ {
+ pNode = FindNode( lNode, wxT( "pt" ) );
+
+ if( pNode )
+ {
+ SetPosition( pNode->GetNodeContent(), m_defaultMeasurementUnit,
+ &x, &y, aActualConversion );
+
+ if( FindOutlinePoint( &m_boardOutline, wxRealPoint( x, y) ) == -1 )
+ m_boardOutline.Add( new wxRealPoint( x, y ) );
+ }
+
+ if( pNode )
+ pNode = pNode->GetNext();
+
+ if( pNode )
+ {
+ SetPosition( pNode->GetNodeContent(), m_defaultMeasurementUnit,
+ &x, &y, aActualConversion );
+
+ if( FindOutlinePoint( &m_boardOutline, wxRealPoint( x, y) ) == -1 )
+ m_boardOutline.Add( new wxRealPoint( x, y ) );
+ }
+ }
+
+ lNode = lNode->GetNext();
+ }
+
+ //m_boardOutline.Sort( cmpFunc );
+ // sort vertices according to the distances between them
+ if( m_boardOutline.GetCount() > 3 )
+ {
+ for( i = 0; i < (int) m_boardOutline.GetCount() - 1; i++ )
+ {
+ minDistance = GetDistance( m_boardOutline[i], m_boardOutline[i + 1] );
+ targetInd = i + 1;
+
+ for( j = i + 2; j < (int) m_boardOutline.GetCount(); j++ )
+ {
+ distance = GetDistance( m_boardOutline[i], m_boardOutline[j] );
+ if( distance < minDistance )
+ {
+ minDistance = distance;
+ targetInd = j;
+ }
+ }
+
+ xchgPoint = m_boardOutline[i + 1];
+ m_boardOutline[i + 1] = m_boardOutline[targetInd];
+ m_boardOutline[targetInd] = xchgPoint;
+ }
+ }
+
+ break;
+ }
+ }
+
+ iNode = iNode->GetNext();
+ }
+ }
+}
+
+void PCB::Parse( wxStatusBar* aStatusBar, wxXmlDocument* aXmlDoc, wxString aActualConversion )
+{
+ XNODE* aNode;//, *aaNode;
+ PCB_NET* net;
+ PCB_COMPONENT* comp;
+ PCB_MODULE* module;
+ wxString compRef, pinRef, layerName, layerType;
+ int i, j, netCode;
+
+ // Defaut measurement units
+ aNode = FindNode( (XNODE *)aXmlDoc->GetRoot(), wxT( "asciiHeader" ) );
+
+ if( aNode )
+ {
+ aNode = FindNode( aNode, wxT( "fileUnits" ) );
+
+ if( aNode )
+ {
+ m_defaultMeasurementUnit = aNode->GetNodeContent().Lower();
+ m_defaultMeasurementUnit.Trim( true );
+ m_defaultMeasurementUnit.Trim( false );
+ }
+ }
+
+ // Determine layers stackup
+ aNode = FindNode( (XNODE *)aXmlDoc->GetRoot(), wxT( "pcbDesign" ) );
+
+ /*if( aNode )
+ {
+ aNode = FindNode( aNode, wxT( "layersStackup" ) );
+
+ if( aNode )
+ {
+ aNode = FindNode( aNode, wxT( "layerStackupData" ) );
+
+ while( aNode )
+ {
+ if( aNode->GetName() == wxT( "layerStackupData" ) )
+ {
+ aaNode = FindNode( aNode, wxT( "layerStackupName" ) );
+
+ if( aaNode ) {
+ aaNode->GetAttribute( wxT( "Name" ), &layerName );
+ layerName = layerName.MakeUpper();
+ m_layersStackup.Add( layerName );
+ }
+ }
+
+ aNode = aNode->GetNext();
+ }
+ }
+ }*/
+
+ if( aNode )
+ {
+ aNode = FindNode( aNode, wxT( "layerDef" ) );
+
+ while( aNode )
+ {
+ if( aNode->GetName() == wxT( "layerDef" ) )
+ {
+ if( FindNode( aNode, wxT( "layerType" ) ) )
+ {
+ layerType = FindNode( aNode,
+ wxT( "layerType" ) )->GetNodeContent().Trim( false );
+
+ if( layerType == wxT( "Signal" ) || layerType == wxT( "Plane" ) )
+ {
+ aNode->GetAttribute( wxT( "Name" ), &layerName );
+ layerName = layerName.MakeUpper();
+ m_layersStackup.Add( layerName );
+ }
+ }
+ }
+
+ aNode = aNode->GetNext();
+ }
+ }
+
+ // Layers mapping
+ aNode = FindNode( (XNODE *)aXmlDoc->GetRoot(), wxT( "pcbDesign" ) );
+
+ if( aNode )
+ {
+ aNode = FindNode( aNode, wxT( "layerDef" ) );
+
+ while( aNode )
+ {
+ if( aNode->GetName() == wxT( "layerDef" ) )
+ MapLayer( aNode );
+
+ aNode = aNode->GetNext();
+ }
+ }
+
+ GetBoardOutline( aXmlDoc, aActualConversion );
+
+ // NETLIST
+ // aStatusBar->SetStatusText( wxT( "Loading NETLIST " ) );
+
+ aNode = FindNode( (XNODE *)aXmlDoc->GetRoot(), wxT( "netlist" ) );
+
+ if( aNode )
+ {
+ aNode = FindNode( aNode, wxT( "net" ) );
+
+ netCode = 1;
+
+ while( aNode )
+ {
+ net = new PCB_NET( netCode++ );
+ net->Parse( aNode );
+ m_pcbNetlist.Add( net );
+
+ aNode = aNode->GetNext();
+ }
+ }
+
+ // BOARD FILE
+ // aStatusBar->SetStatusText( wxT( "Loading BOARD DEFINITION " ) );
+
+ aNode = FindNode( (XNODE *)aXmlDoc->GetRoot(), wxT( "pcbDesign" ) );
+
+ if( aNode )
+ {
+ // COMPONENTS AND OBJECTS
+ aNode = aNode->GetChildren();
+
+ while( aNode )
+ {
+ // Components/modules
+ if( aNode->GetName() == wxT( "multiLayer" ) )
+ DoPCBComponents( aNode, aXmlDoc, aActualConversion, aStatusBar );
+
+ // objects
+ if( aNode->GetName() == wxT( "layerContents" ) )
+ DoLayerContentsObjects( aNode, NULL, &m_pcbComponents, aStatusBar,
+ m_defaultMeasurementUnit, aActualConversion );
+
+ aNode = aNode->GetNext();
+ }
+
+ // POSTPROCESS -- SET NETLIST REFERENCES
+ // aStatusBar->SetStatusText( wxT( "Processing NETLIST " ) );
+
+ for( i = 0; i < (int) m_pcbNetlist.GetCount(); i++ )
+ {
+ net = m_pcbNetlist[i];
+
+ for( j = 0; j < (int) net->m_netNodes.GetCount(); j++ )
+ {
+ compRef = net->m_netNodes[j]->m_compRef;
+ compRef.Trim( false );
+ compRef.Trim( true );
+ pinRef = net->m_netNodes[j]->m_pinRef;
+ pinRef.Trim( false );
+ pinRef.Trim( true );
+ ConnectPinToNet( compRef, pinRef, net->m_name );
+ }
+ }
+
+ // POSTPROCESS -- FLIP COMPONENTS
+ for( i = 0; i < (int) m_pcbComponents.GetCount(); i++ )
+ {
+ if( m_pcbComponents[i]->m_objType == wxT( 'M' ) )
+ ( (PCB_MODULE*) m_pcbComponents[i] )->Flip();
+ }
+
+ // POSTPROCESS -- SET/OPTIMIZE NEW PCB POSITION
+ // aStatusBar->SetStatusText( wxT( "Optimizing BOARD POSITION " ) );
+
+ m_sizeX = 10000000;
+ m_sizeY = 0;
+
+ for( i = 0; i < (int) m_pcbComponents.GetCount(); i++ )
+ {
+ comp = m_pcbComponents[i];
+
+ if( comp->m_positionY < m_sizeY )
+ m_sizeY = comp->m_positionY; // max Y
+
+ if( comp->m_positionX < m_sizeX && comp->m_positionX > 0 )
+ m_sizeX = comp->m_positionX; // Min X
+ }
+
+ m_sizeY -= 10000;
+ m_sizeX -= 10000;
+ // aStatusBar->SetStatusText( wxT( " POSITIONING POSTPROCESS " ) );
+
+ for( i = 0; i < (int) m_pcbComponents.GetCount(); i++ )
+ m_pcbComponents[i]->SetPosOffset( -m_sizeX, -m_sizeY );
+
+ m_sizeX = 0;
+ m_sizeY = 0;
+
+ for( i = 0; i < (int) m_pcbComponents.GetCount(); i++ )
+ {
+ comp = m_pcbComponents[i];
+
+ if( comp->m_positionY < m_sizeY )
+ m_sizeY = comp->m_positionY; // max Y
+
+ if( comp->m_positionX > m_sizeX )
+ m_sizeX = comp->m_positionX; // Min X
+ }
+
+ // SHEET SIZE CALCULATION
+ m_sizeY = -m_sizeY; // it is in absolute units
+ m_sizeX += 10000;
+ m_sizeY += 10000;
+
+ // A4 is minimum $Descr A4 11700 8267
+ if( m_sizeX < 11700 )
+ m_sizeX = 11700;
+
+ if( m_sizeY < 8267 )
+ m_sizeY = 8267;
+ }
+ else
+ {
+ // LIBRARY FILE
+ // aStatusBar->SetStatusText( wxT( "Processing LIBRARY FILE " ) );
+
+ aNode = FindNode( (XNODE *)aXmlDoc->GetRoot(), wxT( "library" ) );
+
+ if( aNode )
+ {
+ aNode = FindNode( aNode, wxT( "compDef" ) );
+
+ while( aNode )
+ {
+ // aStatusBar->SetStatusText( wxT( "Processing COMPONENTS " ) );
+
+ if( aNode->GetName() == wxT( "compDef" ) )
+ {
+ module = new PCB_MODULE( this, m_board );
+ module->Parse( aNode, aStatusBar, m_defaultMeasurementUnit,
+ aActualConversion );
+ m_pcbComponents.Add( module );
+ }
+
+ aNode = aNode->GetNext();
+ }
+ }
+ }
+}
+
+
+void PCB::AddToBoard()
+{
+ int i;
+ PCB_NET* net;
+
+ m_board->SetCopperLayerCount( m_layersStackup.GetCount() );
+
+ for( i = 0; i < (int) m_pcbNetlist.GetCount(); i++ )
+ {
+ net = m_pcbNetlist[i];
+
+ m_board->AppendNet( new NETINFO_ITEM( m_board, net->m_name, net->m_netCode ) );
+ }
+
+ for( i = 0; i < (int) m_pcbComponents.GetCount(); i++ )
+ {
+ m_pcbComponents[i]->AddToBoard();
+ }
+}
+
+} // namespace PCAD2KICAD
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb.h b/pcbnew/pcad2kicadpcb_plugin/pcb.h
new file mode 100644
index 0000000..5d566ff
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb.h
@@ -0,0 +1,92 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb.h
+ */
+
+#ifndef pcb_H_
+#define pcb_H_
+
+#include <wx/wx.h>
+#include <xnode.h>
+
+#include <pcb_module.h>
+#include <pcb_net.h>
+
+namespace PCAD2KICAD {
+
+#define MAX_PCAD_LAYER_QTY 32
+
+class PCB : public PCB_MODULE, public PCB_CALLBACKS
+{
+public:
+ PCB_COMPONENTS_ARRAY m_pcbComponents; // PCB Modules,Lines,Routes,Texts, .... and so on
+ PCB_NETS_ARRAY m_pcbNetlist; // net objects collection
+ wxString m_defaultMeasurementUnit;
+ TLAYER m_layersMap[MAX_PCAD_LAYER_QTY]; // flexible layers mapping
+ int m_sizeX;
+ int m_sizeY;
+
+ PCB( BOARD* aBoard );
+ ~PCB();
+
+ LAYER_ID GetKiCadLayer( int aPCadLayer );
+ LAYER_TYPE_T GetLayerType( int aPCadLayer );
+ wxString GetLayerNetNameRef( int aPCadLayer );
+ int GetNewTimestamp();
+ int GetNetCode( wxString aNetName );
+
+ void Parse( wxStatusBar* aStatusBar,
+ wxXmlDocument* aXmlDoc,
+ wxString aActualConversion );
+
+ void AddToBoard();
+
+private:
+ int m_timestamp_cnt;
+ wxArrayString m_layersStackup;
+
+ XNODE* FindCompDefName( XNODE* aNode, wxString aName );
+ void SetTextProperty( XNODE* aNode,
+ TTEXTVALUE* aTextValue,
+ wxString aPatGraphRefName,
+ wxString aXmlName,
+ wxString aActualConversion );
+ void DoPCBComponents( XNODE* aNode,
+ wxXmlDocument* aXmlDoc,
+ wxString aActualConversion,
+ wxStatusBar* aStatusBar );
+ void ConnectPinToNet( wxString aCr, wxString aPr, wxString aNetName );
+ int FindLayer( wxString aLayerName );
+ void MapLayer( XNODE* aNode );
+ int FindOutlinePoint( VERTICES_ARRAY* aOutline, wxRealPoint aPoint );
+ double GetDistance( wxRealPoint* aPoint1, wxRealPoint* aPoint2 );
+ void GetBoardOutline( wxXmlDocument* aXmlDoc, wxString aActualConversion );
+};
+
+} // namespace PCAD2KICAD
+
+#endif // pcb_H_
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_arc.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_arc.cpp
new file mode 100644
index 0000000..d4395ad
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_arc.cpp
@@ -0,0 +1,193 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_arc.cpp
+ */
+
+#include <wx/wx.h>
+#include <wx/config.h>
+
+#include <common.h>
+#include <trigo.h>
+
+#include <pcb_arc.h>
+
+namespace PCAD2KICAD {
+
+PCB_ARC::PCB_ARC( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : PCB_COMPONENT( aCallbacks, aBoard )
+{
+ m_objType = wxT( 'A' );
+ m_startX = 0;
+ m_startY = 0;
+ m_angle = 0;
+ m_width = 0;
+}
+
+
+PCB_ARC::~PCB_ARC()
+{
+}
+
+
+void PCB_ARC::Parse( XNODE* aNode,
+ int aLayer,
+ wxString aDefaultMeasurementUnit,
+ wxString aActualConversion )
+{
+ XNODE* lNode;
+ double a = 0.0;
+ int r = 0;
+ int endX = 0;
+ int endY = 0;
+
+ m_PCadLayer = aLayer;
+ m_KiCadLayer = GetKiCadLayer();
+
+ if( FindNode( aNode, wxT( "width" ) ) )
+ SetWidth( FindNode( aNode, wxT( "width" ) )->GetNodeContent(),
+ aDefaultMeasurementUnit, &m_width, aActualConversion );
+
+ if( aNode->GetName() == wxT( "triplePointArc" ) )
+ {
+ // center point
+ lNode = FindNode( aNode, wxT( "pt" ) );
+
+ if( lNode )
+ SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
+ &m_positionX, &m_positionY, aActualConversion );
+
+ // start point
+ if( lNode )
+ lNode = lNode->GetNext();
+
+ if( lNode )
+ SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
+ &m_startX, &m_startY, aActualConversion );
+
+ // end point
+ if( lNode )
+ lNode = lNode->GetNext();
+
+ if( lNode )
+ SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
+ &endX, &endY, aActualConversion );
+
+ if( m_startX == endX && m_startY == endY )
+ {
+ m_angle = 3600;
+ }
+ else
+ {
+ double alpha1 = ArcTangente( m_startY - m_positionY, m_startX - m_positionX );
+ double alpha2 = ArcTangente( endY - m_positionY, endX - m_positionX );
+ m_angle = alpha1 - alpha2;
+
+ NORMALIZE_ANGLE_POS( m_angle );
+ }
+ }
+ else if( aNode->GetName() == wxT( "arc" ) )
+ {
+ lNode = FindNode( aNode, wxT( "pt" ) );
+
+ if( lNode )
+ SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
+ &m_positionX, &m_positionY, aActualConversion );
+
+ lNode = FindNode( aNode, wxT( "radius" ) );
+ if( lNode)
+ SetWidth( FindNode( aNode, wxT( "radius" ) )->GetNodeContent(),
+ aDefaultMeasurementUnit, &r, aActualConversion );
+
+
+ lNode = FindNode( aNode, wxT( "startAngle" ) );
+ if( lNode )
+ a = StrToInt1Units( lNode->GetNodeContent() );
+
+ lNode = FindNode( aNode, wxT( "sweepAngle" ) );
+ if( lNode )
+ m_angle = StrToInt1Units( lNode->GetNodeContent() );
+
+ m_startX = m_positionX + KiROUND( cosdecideg( r, a ) );
+ m_startY = m_positionY - KiROUND( sindecideg( r, a ) );
+ }
+}
+
+
+void PCB_ARC::SetPosOffset( int aX_offs, int aY_offs )
+{
+ PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs );
+
+ m_startX += aX_offs;
+ m_startY += aY_offs;
+}
+
+
+void PCB_ARC::Flip()
+{
+ PCB_COMPONENT::Flip();
+
+ m_startX = -m_startX;
+ m_angle = -m_angle;
+
+ m_KiCadLayer = FlipLayer( m_KiCadLayer );
+}
+
+
+void PCB_ARC::AddToModule( MODULE* aModule )
+{
+ if( IsNonCopperLayer( m_KiCadLayer ) )
+ {
+ EDGE_MODULE* arc = new EDGE_MODULE( aModule, S_ARC );
+ aModule->GraphicalItems().PushBack( arc );
+
+ arc->SetAngle( -m_angle );
+ arc->m_Start0 = wxPoint( m_positionX, m_positionY );
+ arc->m_End0 = wxPoint( m_startX, m_startY );
+
+ arc->SetWidth( m_width );
+ arc->SetLayer( m_KiCadLayer );
+
+ arc->SetDrawCoord();
+ }
+}
+
+
+void PCB_ARC::AddToBoard()
+{
+ DRAWSEGMENT* dseg = new DRAWSEGMENT( m_board );
+
+ m_board->Add( dseg, ADD_APPEND );
+
+ dseg->SetShape( S_ARC );
+ dseg->SetTimeStamp( m_timestamp );
+ dseg->SetLayer( m_KiCadLayer );
+ dseg->SetStart( wxPoint( m_positionX, m_positionY ) );
+ dseg->SetEnd( wxPoint( m_startX, m_startY ) );
+ dseg->SetAngle( -m_angle );
+ dseg->SetWidth( m_width );
+}
+
+} // namespace PCAD2KICAD
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_arc.h b/pcbnew/pcad2kicadpcb_plugin/pcb_arc.h
new file mode 100644
index 0000000..8b1c83e
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_arc.h
@@ -0,0 +1,61 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_arc.h
+ */
+
+#ifndef PCB_ARC_H_
+#define PCB_ARC_H_
+
+#include <wx/wx.h>
+
+#include <pcb_component.h>
+
+namespace PCAD2KICAD {
+
+class PCB_ARC : public PCB_COMPONENT
+{
+public:
+ int m_startX;
+ int m_startY;
+ double m_angle;
+ int m_width;
+
+ PCB_ARC( PCB_CALLBACKS* aCallbacks, BOARD* aBoard );
+ ~PCB_ARC();
+
+ virtual void Parse( XNODE* aNode, int aLayer,
+ wxString aDefaultMeasurementUnit, wxString aActualConversion );
+
+ virtual void SetPosOffset( int aX_offs, int aY_offs );
+ virtual void Flip();
+ void AddToModule( MODULE* aModule );
+ void AddToBoard();
+};
+
+} // namespace PCAD2KICAD
+
+#endif // PCB_ARC_H_
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_callbacks.h b/pcbnew/pcad2kicadpcb_plugin/pcb_callbacks.h
new file mode 100644
index 0000000..2c2b5f8
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_callbacks.h
@@ -0,0 +1,64 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_callbacks.h
+ */
+
+#ifndef PCB_CALLBACKS_H_
+#define PCB_CALLBACKS_H_
+
+#include <wx/wx.h>
+#include <layers_id_colors_and_visibility.h>
+
+enum LAYER_TYPE_T
+{
+ LAYER_TYPE_SIGNAL,
+ LAYER_TYPE_NONSIGNAL,
+ LAYER_TYPE_PLANE
+};
+
+typedef struct _TLAYER
+{
+ LAYER_ID KiCadLayer;
+ LAYER_TYPE_T layerType;
+ wxString netNameRef;
+} TLAYER;
+
+namespace PCAD2KICAD
+{
+
+ class PCB_CALLBACKS
+ {
+ public:
+ virtual LAYER_ID GetKiCadLayer( int aPCadLayer ) = 0;
+ virtual LAYER_TYPE_T GetLayerType( int aPCadLayer ) = 0;
+ virtual wxString GetLayerNetNameRef( int aPCadLayer ) = 0;
+ virtual int GetNewTimestamp() = 0;
+ virtual int GetNetCode( wxString netName ) = 0;
+ };
+}
+
+#endif // PCB_CALLBACKS_H_
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_component.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_component.cpp
new file mode 100644
index 0000000..44f5cd9
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_component.cpp
@@ -0,0 +1,80 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_component.cpp
+ */
+
+#include <wx/wx.h>
+#include <wx/config.h>
+
+#include <common.h>
+
+#include <pcb_component.h>
+
+namespace PCAD2KICAD {
+
+PCB_COMPONENT::PCB_COMPONENT( PCB_CALLBACKS* aCallbacks,
+ BOARD* aBoard ) : m_callbacks( aCallbacks ),
+ m_board( aBoard )
+{
+ m_tag = 0;
+ m_objType = wxT( '?' );
+ m_PCadLayer = 0;
+ m_KiCadLayer = F_Cu; // It *has* to be somewhere...
+ m_timestamp = 0;
+ m_positionX = 0;
+ m_positionY = 0;
+ m_rotation = 0;
+ InitTTextValue( &m_name );
+ m_net = wxEmptyString;
+ m_netCode = 0;
+ m_compRef = wxEmptyString;
+ m_patGraphRefName = wxEmptyString;
+}
+
+
+PCB_COMPONENT::~PCB_COMPONENT()
+{
+}
+
+
+void PCB_COMPONENT::AddToModule( MODULE* aModule )
+{
+}
+
+
+void PCB_COMPONENT::SetPosOffset( int aX_offs, int aY_offs )
+{
+ m_positionX += aX_offs;
+ m_positionY += aY_offs;
+}
+
+void PCB_COMPONENT::Flip()
+{
+ m_positionX = -m_positionX;
+}
+
+} // namespace PCAD2KICAD
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_component.h b/pcbnew/pcad2kicadpcb_plugin/pcb_component.h
new file mode 100644
index 0000000..6088fad
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_component.h
@@ -0,0 +1,87 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_component.h
+ */
+
+#ifndef PCB_COMPONENT_H_
+#define PCB_COMPONENT_H_
+
+#include <wx/wx.h>
+#include <wx/file.h>
+
+#include <pcad2kicad_common.h>
+#include <pcb_callbacks.h>
+#include <class_board.h>
+#include <class_module.h>
+#include <class_track.h>
+#include <class_edge_mod.h>
+#include <class_zone.h>
+#include <class_pcb_text.h>
+
+namespace PCAD2KICAD {
+
+// basic parent class for PCB objects
+class PCB_COMPONENT : public wxObject
+{
+public:
+ int m_tag;
+ char m_objType;
+ int m_PCadLayer;
+ LAYER_ID m_KiCadLayer;
+ int m_timestamp;
+ int m_positionX;
+ int m_positionY;
+ int m_rotation;
+ TTEXTVALUE m_name; // name has also private positions, rotations and so on....
+ wxString m_net;
+ int m_netCode;
+ wxString m_compRef; // internal usage for XL parsing
+ wxString m_patGraphRefName; // internal usage for XL parsing
+
+ PCB_COMPONENT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard );
+ ~PCB_COMPONENT();
+
+ virtual void SetPosOffset( int aX_offs, int aY_offs );
+ virtual void Flip();
+ virtual void AddToModule( MODULE* aModule );
+ virtual void AddToBoard() = 0;
+
+ LAYER_ID GetKiCadLayer() { return m_callbacks->GetKiCadLayer( m_PCadLayer ); }
+ int GetNewTimestamp() { return m_callbacks->GetNewTimestamp(); }
+ int GetNetCode( wxString aNetName ) { return m_callbacks->GetNetCode( aNetName ); }
+
+protected:
+ PCB_CALLBACKS* m_callbacks;
+ BOARD* m_board;
+};
+
+WX_DEFINE_ARRAY( PCB_COMPONENT*, PCB_COMPONENTS_ARRAY );
+WX_DEFINE_ARRAY( wxRealPoint*, VERTICES_ARRAY );
+
+} // namespace PCAD2KICAD
+
+#endif // PCB_COMPONENT_H_
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_copper_pour.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_copper_pour.cpp
new file mode 100644
index 0000000..16c7c22
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_copper_pour.cpp
@@ -0,0 +1,112 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_copper_pour.cpp
+ */
+
+#include <wx/wx.h>
+#include <wx/config.h>
+
+#include <common.h>
+
+#include <pcb_copper_pour.h>
+
+namespace PCAD2KICAD {
+
+PCB_COPPER_POUR::PCB_COPPER_POUR( PCB_CALLBACKS* aCallbacks,
+ BOARD* aBoard,
+ int aPCadLayer ) :
+ PCB_POLYGON( aCallbacks, aBoard, aPCadLayer )
+{
+ m_filled = false;
+}
+
+
+PCB_COPPER_POUR::~PCB_COPPER_POUR()
+{
+}
+
+
+bool PCB_COPPER_POUR::Parse( XNODE* aNode,
+ wxString aDefaultMeasurementUnit,
+ wxString aActualConversion,
+ wxStatusBar* aStatusBar )
+{
+ XNODE* lNode;
+ wxString pourType, str, propValue;
+ int pourSpacing, thermalWidth;
+
+ // aStatusBar->SetStatusText( aStatusBar->GetStatusText() + wxT( " CooperPour..." ) );
+
+ //str = FindNode( aNode, wxT( "pourType" ) )->GetNodeContent();
+ //str.Trim( false );
+ //pourType = str.MakeUpper();
+
+ lNode = FindNode( aNode, wxT( "netNameRef" ) );
+
+ if( lNode )
+ {
+ lNode->GetAttribute( wxT( "Name" ), &propValue );
+ propValue.Trim( false );
+ propValue.Trim( true );
+ m_net = propValue;
+ m_netCode = GetNetCode( m_net );
+ }
+
+ if( FindNode( aNode, wxT( "width" ) ) )
+ SetWidth( FindNode( aNode, wxT( "width" ) )->GetNodeContent(),
+ aDefaultMeasurementUnit, &m_width, aActualConversion );
+
+ if( FindNode( aNode, wxT( "pourSpacing" ) ) )
+ SetWidth( FindNode( aNode, wxT( "pourSpacing" ) )->GetNodeContent(),
+ aDefaultMeasurementUnit, &pourSpacing, aActualConversion );
+
+ if( FindNode( aNode, wxT( "thermalWidth" ) ) )
+ SetWidth( FindNode( aNode, wxT( "thermalWidth" ) )->GetNodeContent(),
+ aDefaultMeasurementUnit, &thermalWidth, aActualConversion );
+
+ if( FindNode( aNode, wxT( "island" ) ) )
+ m_filled = true;
+
+ lNode = FindNode( aNode, wxT( "pcbPoly" ) );
+
+ if( lNode )
+ {
+ // retrieve copper pour outline
+ FormPolygon( lNode, &m_outline, aDefaultMeasurementUnit, aActualConversion );
+
+ m_positionX = m_outline[0]->x;
+ m_positionY = m_outline[0]->y;
+ }
+ else
+ {
+ return false;
+ }
+
+ return true;
+}
+
+} // namespace PCAD2KICAD
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_copper_pour.h b/pcbnew/pcad2kicadpcb_plugin/pcb_copper_pour.h
new file mode 100644
index 0000000..209b75f
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_copper_pour.h
@@ -0,0 +1,54 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_copper_pour.h
+ */
+
+#ifndef PCB_COPPER_POUR_H_
+#define PCB_COPPER_POUR_H_
+
+#include <wx/wx.h>
+
+#include <pcb_polygon.h>
+
+namespace PCAD2KICAD {
+
+class PCB_COPPER_POUR : public PCB_POLYGON
+{
+public:
+
+ PCB_COPPER_POUR( PCB_CALLBACKS* aCallbacks, BOARD* aBoard, int aPCadLayer );
+ ~PCB_COPPER_POUR();
+
+ virtual bool Parse( XNODE* aNode,
+ wxString aDefaultMeasurementUnit,
+ wxString aActualConversion,
+ wxStatusBar* aStatusBar );
+};
+
+} // namespace PCAD2KICAD
+
+#endif // PCB_COPPER_POUR_H_
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_cutout.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_cutout.cpp
new file mode 100644
index 0000000..4499783
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_cutout.cpp
@@ -0,0 +1,74 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_cutout.cpp
+ */
+
+#include <wx/wx.h>
+#include <wx/config.h>
+
+#include <pcb_cutout.h>
+
+namespace PCAD2KICAD {
+
+PCB_CUTOUT::PCB_CUTOUT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard, int aPCadLayer ) :
+ PCB_POLYGON( aCallbacks, aBoard, aPCadLayer )
+{
+ m_objType = wxT( 'C' );
+}
+
+
+PCB_CUTOUT::~PCB_CUTOUT()
+{
+}
+
+
+bool PCB_CUTOUT::Parse( XNODE* aNode,
+ wxString aDefaultMeasurementUnit,
+ wxString aActualConversion )
+{
+ XNODE* lNode;
+
+ lNode = FindNode( aNode, wxT( "pcbPoly" ) );
+
+ if( lNode )
+ {
+ // retrieve cutout outline
+ FormPolygon( lNode, &m_outline, aDefaultMeasurementUnit, aActualConversion );
+
+ m_positionX = m_outline[0]->x;
+ m_positionY = m_outline[0]->y;
+ }
+ else
+ {
+ return false;
+ }
+
+ return true;
+}
+
+
+} // namespace PCAD2KICAD
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_cutout.h b/pcbnew/pcad2kicadpcb_plugin/pcb_cutout.h
new file mode 100644
index 0000000..9f8fa6b
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_cutout.h
@@ -0,0 +1,53 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_cutout.h
+ */
+
+#ifndef PCB_CUTOUT_H_
+#define PCB_CUTOUT_H_
+
+#include <wx/wx.h>
+
+#include <pcb_polygon.h>
+
+namespace PCAD2KICAD {
+
+class PCB_CUTOUT : public PCB_POLYGON
+{
+public:
+
+ PCB_CUTOUT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard, int aPCadLayer );
+ ~PCB_CUTOUT();
+
+ virtual bool Parse( XNODE* aNode,
+ wxString aDefaultMeasurementUnit,
+ wxString actualConversion );
+};
+
+} // namespace PCAD2KICAD
+
+#endif // PCB_CUTOUT_H_
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_keepout.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_keepout.cpp
new file mode 100644
index 0000000..d6305b3
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_keepout.cpp
@@ -0,0 +1,76 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008, 2012 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_keepout.cpp
+ */
+
+#include <wx/wx.h>
+#include <wx/config.h>
+
+#include <common.h>
+
+#include <pcb_keepout.h>
+
+namespace PCAD2KICAD {
+
+PCB_KEEPOUT::PCB_KEEPOUT( PCB_CALLBACKS* aCallbacks,
+ BOARD* aBoard,
+ int aPCadLayer ) :
+ PCB_POLYGON( aCallbacks, aBoard, aPCadLayer )
+{
+ m_objType = wxT( 'K' );
+}
+
+
+PCB_KEEPOUT::~PCB_KEEPOUT()
+{
+}
+
+
+bool PCB_KEEPOUT::Parse( XNODE* aNode,
+ wxString aDefaultMeasurementUnit,
+ wxString aActualConversion )
+{
+ XNODE* lNode;
+
+ lNode = FindNode( aNode, wxT( "pcbPoly" ) );
+
+ if( lNode )
+ {
+ // retrieve keepOut outline
+ FormPolygon( lNode, &m_outline, aDefaultMeasurementUnit, aActualConversion );
+
+ m_positionX = m_outline[0]->x;
+ m_positionY = m_outline[0]->y;
+ }
+ else
+ {
+ return false;
+ }
+
+ return true;
+}
+
+} // namespace PCAD2KICAD
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_keepout.h b/pcbnew/pcad2kicadpcb_plugin/pcb_keepout.h
new file mode 100644
index 0000000..d6b9513
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_keepout.h
@@ -0,0 +1,52 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008, 2012 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_keepout.h
+ */
+
+#ifndef PCB_KEEPOUT_H_
+#define PCB_KEEPOUT_H_
+
+#include <wx/wx.h>
+
+#include <pcb_polygon.h>
+
+namespace PCAD2KICAD {
+
+class PCB_KEEPOUT : public PCB_POLYGON
+{
+public:
+
+ PCB_KEEPOUT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard, int aPCadLayer );
+ ~PCB_KEEPOUT();
+
+ virtual bool Parse( XNODE* aNode,
+ wxString aDefaultMeasurementUnit,
+ wxString aActualConversion );
+};
+
+} // namespace PCAD2KICAD
+
+#endif // PCB_KEEPOUT_H_
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_line.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_line.cpp
new file mode 100644
index 0000000..019029d
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_line.cpp
@@ -0,0 +1,166 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_line.cpp
+ */
+
+#include <wx/wx.h>
+#include <wx/config.h>
+
+#include <common.h>
+
+#include <pcb_line.h>
+
+namespace PCAD2KICAD {
+
+PCB_LINE::PCB_LINE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : PCB_COMPONENT( aCallbacks,
+ aBoard )
+{
+ m_width = 0;
+ m_toX = 0;
+ m_toY = 0;
+ m_objType = wxT( 'L' );
+}
+
+
+PCB_LINE::~PCB_LINE()
+{
+}
+
+
+void PCB_LINE::Parse( XNODE* aNode,
+ int aLayer,
+ wxString aDefaultMeasurementUnit,
+ wxString aActualConversion )
+{
+ XNODE* lNode;
+ wxString propValue;
+
+ m_PCadLayer = aLayer;
+ m_KiCadLayer = GetKiCadLayer();
+ m_positionX = 0;
+ m_positionY = 0;
+ m_toX = 0;
+ m_toY = 0;
+ m_width = 0;
+ lNode = FindNode( aNode, wxT( "pt" ) );
+
+ if( lNode )
+ SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
+ &m_positionX, &m_positionY, aActualConversion );
+
+ if( lNode )
+ lNode = lNode->GetNext();
+
+ if( lNode )
+ SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
+ &m_toX, &m_toY, aActualConversion );
+
+ lNode = FindNode( aNode, wxT( "width" ) );
+
+ if( lNode )
+ SetWidth( lNode->GetNodeContent(), aDefaultMeasurementUnit, &m_width, aActualConversion );
+
+ lNode = FindNode( aNode, wxT( "netNameRef" ) );
+
+ if( lNode )
+ {
+ lNode->GetAttribute( wxT( "Name" ), &propValue );
+ propValue.Trim( false );
+ propValue.Trim( true );
+ m_net = propValue;
+ m_netCode = GetNetCode( m_net );
+ }
+}
+
+
+void PCB_LINE::SetPosOffset( int aX_offs, int aY_offs )
+{
+ PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs );
+
+ m_toX += aX_offs;
+ m_toY += aY_offs;
+}
+
+
+void PCB_LINE::Flip()
+{
+ PCB_COMPONENT::Flip();
+
+ m_toX = -m_toX;
+ m_KiCadLayer = FlipLayer( m_KiCadLayer );
+}
+
+
+void PCB_LINE::AddToModule( MODULE* aModule )
+{
+ if( IsNonCopperLayer( m_KiCadLayer ) )
+ {
+ EDGE_MODULE* segment = new EDGE_MODULE( aModule, S_SEGMENT );
+ aModule->GraphicalItems().PushBack( segment );
+
+ segment->m_Start0 = wxPoint( m_positionX, m_positionY );
+ segment->m_End0 = wxPoint( m_toX, m_toY );
+
+ segment->SetWidth( m_width );
+ segment->SetLayer( m_KiCadLayer );
+
+ segment->SetDrawCoord();
+ }
+}
+
+
+void PCB_LINE::AddToBoard()
+{
+ if( IsCopperLayer( m_KiCadLayer ) )
+ {
+ TRACK* track = new TRACK( m_board );
+ m_board->m_Track.Append( track );
+
+ track->SetTimeStamp( m_timestamp );
+
+ track->SetPosition( wxPoint( m_positionX, m_positionY ) );
+ track->SetEnd( wxPoint( m_toX, m_toY ) );
+
+ track->SetWidth( m_width );
+
+ track->SetLayer( m_KiCadLayer );
+ track->SetNetCode( m_netCode );
+ }
+ else
+ {
+ DRAWSEGMENT* dseg = new DRAWSEGMENT( m_board );
+ m_board->Add( dseg, ADD_APPEND );
+
+ dseg->SetTimeStamp( m_timestamp );
+ dseg->SetLayer( m_KiCadLayer );
+ dseg->SetStart( wxPoint( m_positionX, m_positionY ) );
+ dseg->SetEnd( wxPoint( m_toX, m_toY ) );
+ dseg->SetWidth( m_width );
+ }
+}
+
+} // namespace PCAD2KICAD
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_line.h b/pcbnew/pcad2kicadpcb_plugin/pcb_line.h
new file mode 100644
index 0000000..e24aa38
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_line.h
@@ -0,0 +1,62 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_line.h
+ */
+
+#ifndef PCB_LINE_H_
+#define PCB_LINE_H_
+
+#include <wx/wx.h>
+
+#include <pcb_component.h>
+
+namespace PCAD2KICAD {
+
+// Line , routes and drawings
+class PCB_LINE : public PCB_COMPONENT
+{
+public:
+ int m_width;
+ int m_toX;
+ int m_toY;
+
+ PCB_LINE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard );
+ ~PCB_LINE();
+
+ virtual void Parse( XNODE* aNode,
+ int aLayer,
+ wxString aDefaultMeasurementUnit,
+ wxString aActualConversion );
+ virtual void SetPosOffset( int aX_offs, int aY_offs );
+ virtual void Flip();
+ void AddToModule( MODULE* aModule );
+ void AddToBoard();
+};
+
+} // namespace PCAD2KICAD
+
+#endif // PCB_LINE_H_
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp
new file mode 100644
index 0000000..5bcf7d9
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_module.cpp
@@ -0,0 +1,640 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_module.cpp
+ */
+
+#include <wx/wx.h>
+#include <wx/config.h>
+
+#include <common.h>
+
+#include <pcb_arc.h>
+#include <pcb_copper_pour.h>
+#include <pcb_cutout.h>
+#include <pcb_plane.h>
+#include <pcb_line.h>
+#include <pcb_module.h>
+#include <pcb_pad.h>
+#include <pcb_polygon.h>
+#include <pcb_text.h>
+#include <pcb_via.h>
+
+#include <trigo.h>
+
+namespace PCAD2KICAD {
+
+PCB_MODULE::PCB_MODULE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : PCB_COMPONENT( aCallbacks,
+ aBoard )
+{
+ InitTTextValue( &m_value );
+ m_mirror = 0;
+ m_objType = wxT( 'M' ); // MODULE
+ m_KiCadLayer = F_SilkS; // default
+}
+
+
+PCB_MODULE::~PCB_MODULE()
+{
+ int i;
+
+ for( i = 0; i < (int) m_moduleObjects.GetCount(); i++ )
+ {
+ delete m_moduleObjects[i];
+ }
+}
+
+
+XNODE* PCB_MODULE::FindModulePatternDefName( XNODE* aNode, wxString aName )
+{
+ XNODE* result, * lNode;
+ wxString propValue1, propValue2;
+
+ result = NULL;
+ lNode = FindNode( aNode, wxT( "patternDef" ) );
+
+ while( lNode )
+ {
+ if( lNode->GetName() == wxT( "patternDef" ) )
+ {
+ lNode->GetAttribute( wxT( "Name" ), &propValue1 );
+ FindNode( lNode,
+ wxT( "originalName" ) )->GetAttribute( wxT( "Name" ), &propValue2 );
+
+ if( ValidateName( propValue1 ) == aName
+ || ValidateName( propValue2 ) == aName )
+ {
+ result = lNode;
+ lNode = NULL;
+ }
+ }
+
+ if( lNode )
+ lNode = lNode->GetNext();
+ }
+
+ if( result == NULL )
+ {
+ lNode = FindNode( aNode, wxT( "patternDefExtended" ) ); // New file format
+
+ while( lNode )
+ {
+ if( lNode->GetName() == wxT( "patternDefExtended" ) )
+ {
+ lNode->GetAttribute( wxT( "Name" ), &propValue1 );
+
+ if( ValidateName( propValue1 ) == aName )
+ {
+ result = lNode;
+ lNode = NULL;
+ }
+ }
+
+ if( lNode )
+ lNode = lNode->GetNext();
+ }
+ }
+
+ return result;
+}
+
+
+XNODE* PCB_MODULE::FindPatternMultilayerSection( XNODE* aNode, wxString* aPatGraphRefName )
+{
+ XNODE* result, * pNode, * lNode;
+ wxString propValue, patName;
+
+ result = NULL;
+ pNode = aNode; // pattern;
+ lNode = aNode;
+
+ // calling from library conversion we need to find pattern
+ if( lNode->GetName() == wxT( "compDef" ) )
+ {
+ lNode->GetAttribute( wxT( "Name" ), &propValue );
+ propValue.Trim( false );
+ patName = ValidateName( propValue );
+
+ if( FindNode( lNode, wxT( "attachedPattern" ) ) )
+ {
+ FindNode( FindNode( lNode, wxT( "attachedPattern" ) ),
+ wxT( "patternName" ) )->GetAttribute( wxT( "Name" ), &propValue );
+ propValue.Trim( false );
+ propValue.Trim( true );
+ patName = ValidateName( propValue );
+ }
+
+ lNode = FindModulePatternDefName( lNode->GetParent(), patName );
+ pNode = lNode; // pattern;
+ }
+
+ lNode = NULL;
+
+ if( pNode )
+ lNode = FindNode( pNode, wxT( "multiLayer" ) ); // Old file format
+
+ if( lNode )
+ {
+ *aPatGraphRefName = wxEmptyString; // default
+ result = lNode;
+ }
+ else
+ {
+ // New file format
+
+ if( *aPatGraphRefName == wxEmptyString ) // default
+ {
+ if( FindNode( aNode, wxT( "patternGraphicsNameRef" ) ) )
+ {
+ FindNode( aNode,
+ wxT( "patternGraphicsNameRef" ) )->GetAttribute( wxT( "Name" ),
+ aPatGraphRefName );
+ }
+ }
+
+ if( FindNode( aNode, wxT( "patternGraphicsDef" ) ) )
+ lNode = FindNode( aNode, wxT( "patternGraphicsDef" ) );
+ else
+ lNode = FindNode( pNode, wxT( "patternGraphicsDef" ) );
+
+ if( *aPatGraphRefName == wxEmptyString ) // no patern delection, the first is actual...
+ {
+ if( lNode )
+ {
+ result = FindNode( lNode, wxT( "multiLayer" ) );
+ lNode = NULL;
+ }
+ }
+
+ while( lNode ) // selected by name
+ {
+ if( lNode->GetName() == wxT( "patternGraphicsDef" ) )
+ {
+ FindNode( lNode,
+ wxT( "patternGraphicsNameDef" ) )->GetAttribute( wxT( "Name" ),
+ &propValue );
+
+ if( propValue == *aPatGraphRefName )
+ {
+ result = FindNode( lNode, wxT( "multiLayer" ) );
+ lNode = NULL;
+ }
+ else
+ lNode = lNode->GetNext();
+ }
+ else
+ lNode = lNode->GetNext();
+ }
+ }
+
+ return result;
+}
+
+
+void PCB_MODULE::DoLayerContentsObjects( XNODE* aNode,
+ PCB_MODULE* aPCBModule,
+ PCB_COMPONENTS_ARRAY* aList,
+ wxStatusBar* aStatusBar,
+ wxString aDefaultMeasurementUnit,
+ wxString aActualConversion )
+{
+ PCB_ARC* arc;
+ PCB_POLYGON* polygon;
+ PCB_POLYGON *plane_layer = NULL;
+ PCB_COPPER_POUR* copperPour;
+ PCB_CUTOUT* cutout;
+ PCB_PLANE* plane;
+ VERTICES_ARRAY* plane_layer_polygon;
+ PCB_LINE* line;
+ PCB_TEXT* text;
+ XNODE* lNode, * tNode;
+ wxString propValue;
+ long long i;
+ int PCadLayer;
+ long num = 0;
+
+ i = 0;
+ // aStatusBar->SetStatusText( wxT( "Processing LAYER CONTENT OBJECTS " ) );
+ if( FindNode( aNode, wxT( "layerNumRef" ) ) )
+ FindNode( aNode, wxT( "layerNumRef" ) )->GetNodeContent().ToLong( &num );
+
+ PCadLayer = (int) num;
+
+ if( m_callbacks->GetLayerType( PCadLayer ) == LAYER_TYPE_PLANE )
+ {
+ plane_layer = new PCB_POLYGON( m_callbacks, m_board, PCadLayer );
+ plane_layer->AssignNet( m_callbacks->GetLayerNetNameRef( PCadLayer ) );
+ plane_layer->SetOutline( &m_boardOutline );
+ aList->Add( plane_layer );
+
+ // fill the polygon with the same contour as its outline is
+ //plane_layer->AddIsland( &m_boardOutline );
+ }
+
+ lNode = aNode->GetChildren();
+
+ while( lNode )
+ {
+ i++;
+ // aStatusBar->SetStatusText( wxString::Format( "Processing LAYER CONTENT OBJECTS :%lld",
+ // i ) );
+
+ if( lNode->GetName() == wxT( "line" ) )
+ {
+ line = new PCB_LINE( m_callbacks, m_board );
+ line->Parse( lNode, PCadLayer, aDefaultMeasurementUnit, aActualConversion );
+ aList->Add( line );
+ }
+
+ if( lNode->GetName() == wxT( "text" ) )
+ {
+ text = new PCB_TEXT( m_callbacks, m_board );
+ text->Parse( lNode, PCadLayer, aDefaultMeasurementUnit, aActualConversion );
+ aList->Add( text );
+ }
+
+ // added as Sergeys request 02/2008
+ if( lNode->GetName() == wxT( "attr" ) )
+ {
+ // assign fonts to Module Name,Value,Type,....s
+ lNode->GetAttribute( wxT( "Name" ), &propValue );
+ propValue.Trim( false );
+ propValue.Trim( true );
+
+ if( propValue == wxT( "RefDes" ) )
+ {
+ tNode = FindNode( lNode, wxT( "textStyleRef" ) );
+
+ if( tNode && aPCBModule )
+ {
+ // TODO: to understand and may be repair
+ // Alexander Lunev: originally in Delphi version of the project there was
+ // a strange access to pcbModule->m_name (it was global variable). This access
+ // is necessary when the function DoLayerContentsObjects() is called from
+ // function CreatePCBModule(). However it is not clear whether the access is
+ // required when the function DoLayerContentsObjects() is called from
+ // function ProcessXMLtoPCBLib().
+ SetFontProperty( tNode,
+ &aPCBModule->m_name,
+ aDefaultMeasurementUnit,
+ aActualConversion );
+ }
+ }
+ }
+
+ // added as Sergeys request 02/2008
+ if( lNode->GetName() == wxT( "arc" ) || lNode->GetName() == wxT( "triplePointArc" ) )
+ {
+ arc = new PCB_ARC( m_callbacks, m_board );
+ arc->Parse( lNode, PCadLayer, aDefaultMeasurementUnit, aActualConversion );
+ aList->Add( arc );
+ }
+
+ if( lNode->GetName() == wxT( "pcbPoly" ) )
+ {
+ if( m_callbacks->GetLayerType( PCadLayer ) == LAYER_TYPE_PLANE )
+ {
+ plane_layer_polygon = new VERTICES_ARRAY;
+ wxASSERT( plane_layer );
+ plane_layer->FormPolygon( lNode, plane_layer_polygon, aDefaultMeasurementUnit, aActualConversion );
+ plane_layer->m_cutouts.Add( plane_layer_polygon );
+ }
+ else
+ {
+ polygon = new PCB_POLYGON( m_callbacks, m_board, PCadLayer );
+ if( polygon->Parse( lNode,
+ aDefaultMeasurementUnit,
+ aActualConversion,
+ aStatusBar ) )
+ aList->Add( polygon );
+ else
+ delete polygon;
+ }
+ }
+
+ if( lNode->GetName() == wxT( "copperPour95" ) )
+ {
+ copperPour = new PCB_COPPER_POUR( m_callbacks, m_board, PCadLayer );
+
+ if( copperPour->Parse( lNode, aDefaultMeasurementUnit, aActualConversion,
+ aStatusBar ) )
+ aList->Add( copperPour );
+ else
+ delete copperPour;
+ }
+
+ if( lNode->GetName() == wxT( "polyCutOut" ) )
+ {
+ cutout = new PCB_CUTOUT( m_callbacks, m_board, PCadLayer );
+
+ if( cutout->Parse( lNode, aDefaultMeasurementUnit, aActualConversion ) )
+ aList->Add( cutout );
+ else
+ delete cutout;
+ }
+
+ if( lNode->GetName() == wxT( "planeObj" ) )
+ {
+ plane = new PCB_PLANE( m_callbacks, m_board, PCadLayer );
+
+ if( plane->Parse( lNode, aDefaultMeasurementUnit, aActualConversion,
+ aStatusBar ) )
+ aList->Add( plane );
+ else
+ delete plane;
+ }
+
+ lNode = lNode->GetNext();
+ }
+}
+
+
+void PCB_MODULE::SetPadName( wxString aPin, wxString aName )
+{
+ int i;
+ long num;
+
+ aPin.ToLong( &num );
+
+ for( i = 0; i < (int) m_moduleObjects.GetCount(); i++ )
+ {
+ if( m_moduleObjects[i]->m_objType == wxT( 'P' ) )
+ if( ( (PCB_PAD*) m_moduleObjects[i] )->m_number == num )
+ ( (PCB_PAD*) m_moduleObjects[i] )->m_name.text = aName;
+
+
+ }
+}
+
+
+void PCB_MODULE::Parse( XNODE* aNode, wxStatusBar* aStatusBar,
+ wxString aDefaultMeasurementUnit, wxString aActualConversion )
+{
+ XNODE* lNode, * tNode, * mNode;
+ PCB_PAD* pad;
+ PCB_VIA* via;
+ wxString propValue, str;
+
+ FindNode( aNode, wxT( "originalName" ) )->GetAttribute( wxT( "Name" ),
+ &propValue );
+ propValue.Trim( false );
+ m_name.text = propValue;
+
+ // aStatusBar->SetStatusText( wxT( "Creating Component : " ) + m_name.text );
+ lNode = aNode;
+ lNode = FindPatternMultilayerSection( lNode, &m_patGraphRefName );
+
+ if( lNode )
+ {
+ tNode = lNode;
+ tNode = tNode->GetChildren();
+
+ while( tNode )
+ {
+ if( tNode->GetName() == wxT( "pad" ) )
+ {
+ pad = new PCB_PAD( m_callbacks, m_board );
+ pad->Parse( tNode, aDefaultMeasurementUnit, aActualConversion );
+ m_moduleObjects.Add( pad );
+ }
+
+ if( tNode->GetName() == wxT( "via" ) )
+ {
+ via = new PCB_VIA( m_callbacks, m_board );
+ via->Parse( tNode, aDefaultMeasurementUnit, aActualConversion );
+ m_moduleObjects.Add( via );
+ }
+
+ tNode = tNode->GetNext();
+ }
+ }
+
+ if( lNode )
+ lNode = lNode->GetParent();
+
+ if( lNode )
+ lNode = FindNode( lNode, wxT( "layerContents" ) );
+
+ while( lNode )
+ {
+ if( lNode->GetName() == wxT( "layerContents" ) )
+ DoLayerContentsObjects( lNode, this, &m_moduleObjects, aStatusBar,
+ aDefaultMeasurementUnit, aActualConversion );
+
+ lNode = lNode->GetNext();
+ }
+
+ // map pins
+ lNode = FindPinMap( aNode );
+
+ if( lNode )
+ {
+ mNode = lNode->GetChildren();
+
+ while( mNode )
+ {
+ if( mNode->GetName() == wxT( "padNum" ) )
+ {
+ str = mNode->GetNodeContent();
+ mNode = mNode->GetNext();
+
+ if( !mNode )
+ break;
+
+ mNode->GetAttribute( wxT( "Name" ), &propValue );
+ SetPadName( str, propValue );
+ mNode = mNode->GetNext();
+ }
+ else
+ {
+ mNode = mNode->GetNext();
+
+ if( !mNode )
+ break;
+
+ mNode = mNode->GetNext();
+ }
+ }
+ }
+}
+
+
+wxString PCB_MODULE::ModuleLayer( int aMirror )
+{
+ wxString result;
+
+ // ///NOT ! {IntToStr(KiCadLayer)} NOT !
+ // / MODULES ARE HARD PLACED ON COMPONENT OR COPPER LAYER.
+ // / IsFLIPPED--> MIRROR attribute is decision Point!!!
+
+ if( aMirror == 0 )
+ result = wxT( "15" ); // Components side
+ else
+ result = wxT( "0" ); // Copper side
+
+ return result;
+}
+
+
+void PCB_MODULE::AddToBoard()
+{
+ int i;
+ int r;
+
+ // transform text positions
+ CorrectTextPosition( &m_name );
+ RotatePoint( &m_name.correctedPositionX, &m_name.correctedPositionY,
+ (double) -m_rotation );
+
+ CorrectTextPosition( &m_value );
+ RotatePoint( &m_value.correctedPositionX, &m_value.correctedPositionY,
+ (double) -m_rotation );
+
+ MODULE* module = new MODULE( m_board );
+ m_board->Add( module, ADD_APPEND );
+
+ module->SetPosition( wxPoint( m_positionX, m_positionY ) );
+ module->SetLayer( m_mirror ? B_Cu : F_Cu );
+ module->SetOrientation( m_rotation );
+ module->SetTimeStamp( 0 );
+ module->SetLastEditTime( 0 );
+
+ module->SetFPID( FPID( m_compRef ) );
+
+ module->SetAttributes( MOD_DEFAULT | MOD_CMS );
+
+ // reference text
+ TEXTE_MODULE* ref_text = &module->Reference();
+
+ ref_text->SetText( m_name.text );
+ ref_text->SetType( TEXTE_MODULE::TEXT_is_REFERENCE );
+
+ ref_text->SetPos0( wxPoint( m_name.correctedPositionX, m_name.correctedPositionY ) );
+ ref_text->SetSize( wxSize( KiROUND( m_name.textHeight / 2 ),
+ KiROUND( m_name.textHeight / 1.5 ) ) );
+
+ r = m_name.textRotation - m_rotation;
+ ref_text->SetOrientation( r );
+
+ ref_text->SetThickness( m_name.textstrokeWidth );
+
+ ref_text->SetMirrored( m_name.mirror );
+ ref_text->SetVisible( m_name.textIsVisible );
+
+ ref_text->SetLayer( m_KiCadLayer );
+
+ // Calculate the actual position.
+ ref_text->SetDrawCoord();
+
+ // value text
+ TEXTE_MODULE* val_text = &module->Value();
+
+ val_text->SetText( m_value.text );
+ val_text->SetType( TEXTE_MODULE::TEXT_is_VALUE );
+
+ val_text->SetPos0( wxPoint( m_value.correctedPositionX, m_value.correctedPositionY ) );
+ val_text->SetSize( wxSize( KiROUND( m_value.textHeight / 2 ),
+ KiROUND( m_value.textHeight / 1.5 ) ) );
+
+ r = m_value.textRotation - m_rotation;
+ val_text->SetOrientation( r );
+
+ val_text->SetThickness( m_value.textstrokeWidth );
+
+ val_text->SetMirrored( m_value.mirror );
+ val_text->SetVisible( m_value.textIsVisible );
+
+ val_text->SetLayer( m_KiCadLayer );
+
+ // Calculate the actual position.
+ val_text->SetDrawCoord();
+
+ // TEXTS
+ for( i = 0; i < (int) m_moduleObjects.GetCount(); i++ )
+ {
+ if( m_moduleObjects[i]->m_objType == wxT( 'T' ) )
+ {
+ ( (PCB_TEXT*) m_moduleObjects[i] )->m_tag = i + 2;
+ m_moduleObjects[i]->AddToModule( module );
+ }
+ }
+
+ // MODULE LINES
+ for( i = 0; i < (int) m_moduleObjects.GetCount(); i++ )
+ {
+ if( m_moduleObjects[i]->m_objType == wxT( 'L' ) )
+ m_moduleObjects[i]->AddToModule( module );
+ }
+
+ // MODULE Arcs
+ for( i = 0; i < (int) m_moduleObjects.GetCount(); i++ )
+ {
+ if( m_moduleObjects[i]->m_objType == wxT( 'A' ) )
+ m_moduleObjects[i]->AddToModule( module );
+ }
+
+ // PADS
+ for( i = 0; i < (int) m_moduleObjects.GetCount(); i++ )
+ {
+ if( m_moduleObjects[i]->m_objType == wxT( 'P' ) )
+ ( (PCB_PAD*) m_moduleObjects[i] )->AddToModule( module, m_rotation, false );
+ }
+
+ // VIAS
+ for( i = 0; i < (int) m_moduleObjects.GetCount(); i++ )
+ {
+ if( m_moduleObjects[i]->m_objType == wxT( 'V' ) )
+ ( (PCB_VIA*) m_moduleObjects[i] )->AddToModule( module, m_rotation, false );
+ }
+
+ module->CalculateBoundingBox();
+}
+
+
+void PCB_MODULE::Flip()
+{
+ int i;
+
+ if( m_mirror == 1 )
+ {
+ // Flipped
+ m_KiCadLayer = FlipLayer( m_KiCadLayer );
+ m_rotation = -m_rotation;
+
+ for( i = 0; i < (int) m_moduleObjects.GetCount(); i++ )
+ {
+ if( m_moduleObjects[i]->m_objType == wxT( 'L' ) || // lines
+ m_moduleObjects[i]->m_objType == wxT( 'A' ) || // arcs
+ m_moduleObjects[i]->m_objType == wxT( 'P' ) || // pads
+ m_moduleObjects[i]->m_objType == wxT( 'V' ) ) // vias
+ {
+ m_moduleObjects[i]->Flip();
+ }
+ }
+ }
+}
+
+} // namespace PCAD2KICAD
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_module.h b/pcbnew/pcad2kicadpcb_plugin/pcb_module.h
new file mode 100644
index 0000000..27d8d3d
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_module.h
@@ -0,0 +1,75 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_module.h
+ */
+
+#ifndef PCB_MODULE_H_
+#define PCB_MODULE_H_
+
+#include <wx/wx.h>
+
+#include <pcad2kicad_common.h>
+#include <pcb_component.h>
+
+namespace PCAD2KICAD {
+
+class PCB_MODULE : public PCB_COMPONENT
+{
+public:
+ TTEXTVALUE m_value; // has reference (Name from parent) and value
+ PCB_COMPONENTS_ARRAY m_moduleObjects; // set of objects like PCB_LINE, PCB_PAD, PCB_VIA,....
+ int m_mirror;
+ VERTICES_ARRAY m_boardOutline;
+
+ PCB_MODULE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard );
+ ~PCB_MODULE();
+
+ XNODE* FindModulePatternDefName( XNODE* aNode, wxString aName );
+
+ void DoLayerContentsObjects( XNODE* aNode,
+ PCB_MODULE* aPCBModule,
+ PCB_COMPONENTS_ARRAY* aList,
+ wxStatusBar* aStatusBar,
+ wxString aDefaultMeasurementUnit,
+ wxString aActualConversion );
+
+ void SetPadName( wxString aPin, wxString aName );
+
+ virtual void Parse( XNODE* aNode, wxStatusBar* aStatusBar,
+ wxString aDefaultMeasurementUnit, wxString aActualConversion );
+
+ virtual void Flip();
+ void AddToBoard();
+
+private:
+ XNODE* FindPatternMultilayerSection( XNODE* aNode, wxString* aPatGraphRefName );
+ wxString ModuleLayer( int aMirror );
+};
+
+} // namespace PCAD2KICAD
+
+#endif // PCB_MODULE_H_
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_net.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_net.cpp
new file mode 100644
index 0000000..c1dc5ee
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_net.cpp
@@ -0,0 +1,104 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_net.cpp
+ */
+
+#include <wx/wx.h>
+#include <wx/config.h>
+
+#include <pcb_net.h>
+
+namespace PCAD2KICAD {
+
+PCB_NET_NODE::PCB_NET_NODE()
+{
+ m_compRef = wxEmptyString;
+ m_pinRef = wxEmptyString;
+}
+
+
+PCB_NET_NODE::~PCB_NET_NODE()
+{
+}
+
+
+PCB_NET::PCB_NET( int aNetCode ) : m_netCode( aNetCode )
+{
+ m_name = wxEmptyString;
+}
+
+
+PCB_NET::~PCB_NET()
+{
+ int i;
+
+ for( i = 0; i < (int) m_netNodes.GetCount(); i++ )
+ {
+ delete m_netNodes[i];
+ }
+}
+
+
+void PCB_NET::Parse( XNODE* aNode )
+{
+ wxString propValue, s1, s2;
+ PCB_NET_NODE* netNode;
+ XNODE* lNode;
+
+ aNode->GetAttribute( wxT( "Name" ), &propValue );
+ propValue.Trim( false );
+ propValue.Trim( true );
+ m_name = propValue;
+
+ lNode = FindNode( aNode, wxT( "node" ) );
+
+ while( lNode )
+ {
+ lNode->GetAttribute( wxT( "Name" ), &s2 );
+ s2.Trim( false );
+ s1 = wxEmptyString;
+
+ while( s2.Len() > 0 && s2[0] != wxT( ' ' ) )
+ {
+ s1 = s1 + s2[0];
+ s2 = s2.Mid( 1 );
+ }
+
+ netNode = new PCB_NET_NODE;
+ s1.Trim( false );
+ s1.Trim( true );
+ netNode->m_compRef = s1;
+
+ s2.Trim( false );
+ s2.Trim( true );
+ netNode->m_pinRef = s2;
+ m_netNodes.Add( netNode );
+ lNode = lNode->GetNext();
+ }
+}
+
+} // namespace PCAD2KICAD
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_net.h b/pcbnew/pcad2kicadpcb_plugin/pcb_net.h
new file mode 100644
index 0000000..867271d
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_net.h
@@ -0,0 +1,68 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_net.h
+ */
+
+#ifndef PCB_NET_H_
+#define PCB_NET_H_
+
+#include <wx/wx.h>
+
+#include <pcad2kicad_common.h>
+
+namespace PCAD2KICAD {
+
+class PCB_NET_NODE : public wxObject
+{
+public:
+ wxString m_compRef;
+ wxString m_pinRef;
+
+ PCB_NET_NODE();
+ ~PCB_NET_NODE();
+};
+
+WX_DEFINE_ARRAY( PCB_NET_NODE*, PCB_NET_NODES_ARRAY );
+
+class PCB_NET : public wxObject
+{
+public:
+ wxString m_name;
+ int m_netCode;
+ PCB_NET_NODES_ARRAY m_netNodes;
+
+ PCB_NET( int aNetCode );
+ ~PCB_NET();
+
+ void Parse( XNODE* aNode );
+};
+
+WX_DEFINE_ARRAY( PCB_NET*, PCB_NETS_ARRAY );
+
+} // namespace PCAD2KICAD
+
+#endif // PCB_NET_H_
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_pad.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_pad.cpp
new file mode 100644
index 0000000..f1e9b91
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_pad.cpp
@@ -0,0 +1,363 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_pad.cpp
+ */
+
+#include <wx/wx.h>
+#include <wx/config.h>
+#include <trigo.h>
+
+#include <pcb_pad.h>
+
+namespace PCAD2KICAD {
+
+PCB_PAD::PCB_PAD( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : PCB_COMPONENT( aCallbacks, aBoard )
+{
+ m_objType = wxT( 'P' );
+ m_number = 0;
+ m_hole = 0;
+ m_isHolePlated = true;
+ m_defaultPinDes = wxEmptyString;
+}
+
+
+PCB_PAD::~PCB_PAD()
+{
+ int i;
+
+ for( i = 0; i < (int) m_shapes.GetCount(); i++ )
+ {
+ delete m_shapes[i];
+ }
+}
+
+
+void PCB_PAD::Parse( XNODE* aNode, wxString aDefaultMeasurementUnit,
+ wxString aActualConversion )
+{
+ XNODE* lNode, *cNode;
+ long num;
+ wxString propValue, str, emsg;
+ PCB_PAD_SHAPE* padShape;
+
+ m_rotation = 0;
+ lNode = FindNode( aNode, wxT( "padNum" ) );
+
+ if( lNode )
+ {
+ lNode->GetNodeContent().ToLong( &num );
+ m_number = (int) num;
+ }
+
+ lNode = FindNode( aNode, wxT( "padStyleRef" ) );
+
+ if( lNode )
+ {
+ lNode->GetAttribute( wxT( "Name" ), &propValue );
+ propValue.Trim( false );
+ m_name.text = propValue;
+ }
+
+ lNode = FindNode( aNode, wxT( "pt" ) );
+
+ if( lNode )
+ SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
+ &m_positionX, &m_positionY, aActualConversion );
+
+ lNode = FindNode( aNode, wxT( "rotation" ) );
+
+ if( lNode )
+ {
+ str = lNode->GetNodeContent();
+ str.Trim( false );
+ m_rotation = StrToInt1Units( str );
+ }
+
+ lNode = FindNode( aNode, wxT( "netNameRef" ) );
+
+ if( lNode )
+ {
+ lNode->GetAttribute( wxT( "Name" ), &propValue );
+ propValue.Trim( false );
+ propValue.Trim( true );
+ m_net = propValue;
+ m_netCode = GetNetCode( m_net );
+ }
+
+ lNode = FindNode( aNode, wxT( "defaultPinDes" ) );
+
+ if( lNode )
+ {
+ lNode->GetAttribute( wxT( "Name" ), &propValue );
+ //propValue.Trim( false );
+ m_defaultPinDes = propValue;
+ }
+
+ lNode = aNode;
+
+ while( lNode && lNode->GetName() != wxT( "www.lura.sk" ) )
+ lNode = lNode->GetParent();
+
+ lNode = FindNode( lNode, wxT( "library" ) );
+ if ( !lNode )
+ THROW_IO_ERROR( wxT( "Unable to find library section" ) );
+
+ lNode = FindNode( lNode, wxT( "padStyleDef" ) );
+
+ while( lNode )
+ {
+ lNode->GetAttribute( wxT( "Name" ), &propValue );
+
+ if( propValue.IsSameAs( m_name.text, false) )
+ break;
+
+ lNode = lNode->GetNext();
+ }
+
+ if ( !lNode )
+ THROW_IO_ERROR( wxString::Format( wxT( "Unable to find padStyleDef " ) + m_name.text ) );
+
+ cNode = FindNode( lNode, wxT( "holeDiam" ) );
+
+ if( cNode )
+ SetWidth( cNode->GetNodeContent(), aDefaultMeasurementUnit, &m_hole, aActualConversion );
+
+ if( FindNodeGetContent( lNode, wxT( "isHolePlated" ) ) == wxT( "False" ) )
+ m_isHolePlated = false;
+
+ cNode = FindNode( lNode, wxT( "padShape" ) );
+
+ while( cNode )
+ {
+ if( cNode->GetName() == wxT( "padShape" ) )
+ {
+ // we support only Pads on specific layers......
+ // we do not support pads on "Plane", "NonSignal" , "Signal" ... layerr
+ if( FindNode( cNode, wxT( "layerNumRef" ) ) )
+ {
+ padShape = new PCB_PAD_SHAPE( m_callbacks, m_board );
+ padShape->Parse( cNode, aDefaultMeasurementUnit, aActualConversion );
+ m_shapes.Add( padShape );
+ }
+ }
+
+ cNode = cNode->GetNext();
+ }
+}
+
+
+void PCB_PAD::Flip()
+{
+ int i;
+
+ PCB_COMPONENT::Flip();
+
+ if( m_objType == wxT( 'P' ) )
+ m_rotation = -m_rotation;
+
+ for( i = 0; i < (int)m_shapes.GetCount(); i++ )
+ m_shapes[i]->m_KiCadLayer = FlipLayer( m_shapes[i]->m_KiCadLayer );
+}
+
+
+void PCB_PAD::AddToModule( MODULE* aModule, int aRotation, bool aEncapsulatedPad )
+{
+ PCB_PAD_SHAPE* padShape;
+ wxString padShapeName = wxT( "Ellipse" );
+ PAD_ATTR_T padType;
+ int i;
+ int width = 0;
+ int height = 0;
+
+ D_PAD* pad = new D_PAD( aModule );
+
+ if( !m_isHolePlated && m_hole )
+ {
+ // mechanical hole
+ pad->SetShape( PAD_SHAPE_CIRCLE );
+ pad->SetAttribute( PAD_ATTRIB_HOLE_NOT_PLATED );
+
+ pad->SetDrillShape( PAD_DRILL_SHAPE_CIRCLE );
+ pad->SetDrillSize( wxSize( m_hole, m_hole ) );
+ pad->SetSize( wxSize( m_hole, m_hole ) );
+
+ pad->SetLayerSet( LSET::AllCuMask() | LSET( 2, B_Mask, F_Mask ) );
+ }
+ else
+ {
+ ( m_hole ) ? padType = PAD_ATTRIB_STANDARD : padType = PAD_ATTRIB_SMD;
+
+ // form layer mask
+ for( i = 0; i < (int) m_shapes.GetCount(); i++ )
+ {
+ padShape = m_shapes[i];
+
+ if( padShape->m_width > 0 && padShape->m_height > 0 )
+ {
+ if( padShape->m_KiCadLayer == F_Cu ||
+ padShape->m_KiCadLayer == B_Cu )
+ {
+ padShapeName = padShape->m_shape;
+ width = padShape->m_width;
+ height = padShape->m_height;
+
+ // assume this is SMD pad
+ if( padShape->m_KiCadLayer == F_Cu )
+ pad->SetLayerSet( LSET( 3, F_Cu, F_Paste, F_Mask ) );
+ else
+ pad->SetLayerSet( LSET( 3, B_Cu, B_Paste, B_Mask ) );
+ break;
+ }
+ }
+ }
+
+ if( width == 0 || height == 0 )
+ {
+ delete pad;
+ return;
+ }
+
+ if( padType == PAD_ATTRIB_STANDARD )
+ // actually this is a thru-hole pad
+ pad->SetLayerSet( LSET::AllCuMask() | LSET( 2, B_Mask, F_Mask ) );
+
+ pad->SetPadName( m_name.text );
+
+ if( padShapeName == wxT( "Oval" )
+ || padShapeName == wxT( "Ellipse" )
+ || padShapeName == wxT( "MtHole" ) )
+ {
+ if( width != height )
+ pad->SetShape( PAD_SHAPE_OVAL );
+ else
+ pad->SetShape( PAD_SHAPE_CIRCLE );
+ }
+ else if( padShapeName == wxT( "Rect" )
+ || padShapeName == wxT( "RndRect" ) )
+ pad->SetShape( PAD_SHAPE_RECT );
+ else if( padShapeName == wxT( "Polygon" ) )
+ pad->SetShape( PAD_SHAPE_RECT ); // approximation
+
+ pad->SetSize( wxSize( width, height ) );
+ pad->SetDelta( wxSize( 0, 0 ) );
+ pad->SetOrientation( m_rotation + aRotation );
+
+ pad->SetDrillShape( PAD_DRILL_SHAPE_CIRCLE );
+ pad->SetOffset( wxPoint( 0, 0 ) );
+ pad->SetDrillSize( wxSize( m_hole, m_hole ) );
+
+ pad->SetAttribute( padType );
+
+ // Set the proper net code
+ NETINFO_ITEM* netinfo = m_board->FindNet( m_net );
+ if( netinfo == NULL ) // I believe this should not happen, but just in case
+ {
+ // It is a new net
+ netinfo = new NETINFO_ITEM( m_board, m_net );
+ m_board->AppendNet( netinfo );
+ }
+
+ pad->SetNetCode( netinfo->GetNet() );
+ }
+
+ if( !aEncapsulatedPad )
+ {
+ // pad's "Position" is not relative to the module's,
+ // whereas Pos0 is relative to the module's but is the unrotated coordinate.
+ wxPoint padpos( m_positionX, m_positionY );
+ pad->SetPos0( padpos );
+ RotatePoint( &padpos, aModule->GetOrientation() );
+ pad->SetPosition( padpos + aModule->GetPosition() );
+ }
+
+ aModule->Pads().PushBack( pad );
+}
+
+
+void PCB_PAD::AddToBoard()
+{
+ PCB_PAD_SHAPE* padShape;
+ int i;
+ int width = 0;
+ int height = 0;
+
+ if( m_objType == wxT( 'V' ) ) // via
+ {
+ // choose one of the shapes
+ for( i = 0; i < (int) m_shapes.GetCount(); i++ )
+ {
+ padShape = m_shapes[i];
+
+ if( padShape->m_width > 0 && padShape->m_height > 0 )
+ {
+ if( padShape->m_KiCadLayer == F_Cu
+ || padShape->m_KiCadLayer == B_Cu )
+ {
+ width = padShape->m_width;
+ height = padShape->m_height;
+
+ break;
+ }
+ }
+ }
+
+ if( width == 0 || height == 0 )
+ return;
+
+ if( IsCopperLayer( m_KiCadLayer ) )
+ {
+ VIA* via = new VIA( m_board );
+ m_board->m_Track.Append( via );
+
+ via->SetTimeStamp( 0 );
+
+ via->SetPosition( wxPoint( m_positionX, m_positionY ) );
+ via->SetEnd( wxPoint( m_positionX, m_positionY ) );
+
+ via->SetWidth( height );
+ via->SetViaType( VIA_THROUGH );
+ via->SetLayerPair( F_Cu, B_Cu );
+ via->SetDrill( m_hole );
+
+ via->SetLayer( m_KiCadLayer );
+ via->SetNetCode( m_netCode );
+ }
+ }
+ else // pad
+ {
+ MODULE* module = new MODULE( m_board );
+ m_board->Add( module, ADD_APPEND );
+
+ m_name.text = m_defaultPinDes;
+
+ module->SetPosition( wxPoint( m_positionX, m_positionY ) );
+ AddToModule( module, 0, true );
+
+ }
+}
+
+} // namespace PCAD2KICAD
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_pad.h b/pcbnew/pcad2kicadpcb_plugin/pcb_pad.h
new file mode 100644
index 0000000..fa18bd5
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_pad.h
@@ -0,0 +1,64 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_pad.h
+ */
+
+#ifndef PCB_PAD_H_
+#define PCB_PAD_H_
+
+#include <wx/wx.h>
+
+#include <pcb_component.h>
+#include <pcb_pad_shape.h>
+
+namespace PCAD2KICAD {
+
+class PCB_PAD : public PCB_COMPONENT
+{
+public:
+ int m_number;
+ int m_hole;
+ bool m_isHolePlated;
+ PCB_PAD_SHAPES_ARRAY m_shapes;
+
+ PCB_PAD( PCB_CALLBACKS* aCallbacks, BOARD* aBoard );
+ ~PCB_PAD();
+
+ virtual void Parse( XNODE* aNode,
+ wxString aDefaultMeasurementUnit,
+ wxString aActualConversion );
+ virtual void Flip();
+ void AddToModule( MODULE* aModule, int aRotation, bool aEncapsulatedPad );
+ void AddToBoard();
+
+private:
+ wxString m_defaultPinDes;
+};
+
+} // namespace PCAD2KICAD
+
+#endif // PCB_PAD_H_
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_pad_shape.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_pad_shape.cpp
new file mode 100644
index 0000000..699f51f
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_pad_shape.cpp
@@ -0,0 +1,142 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_pad_shape.cpp
+ */
+
+#include <wx/wx.h>
+#include <wx/config.h>
+
+#include <common.h>
+
+#include <pcb_pad_shape.h>
+
+namespace PCAD2KICAD {
+
+PCB_PAD_SHAPE::PCB_PAD_SHAPE( PCB_CALLBACKS* aCallbacks,
+ BOARD* aBoard ) : PCB_COMPONENT( aCallbacks, aBoard )
+{
+ m_shape = wxEmptyString;
+ m_width = 0;
+ m_height = 0;
+}
+
+
+PCB_PAD_SHAPE::~PCB_PAD_SHAPE()
+{
+}
+
+
+void PCB_PAD_SHAPE::Parse( XNODE* aNode,
+ wxString aDefaultMeasurementUnit,
+ wxString aActualConversion )
+{
+ wxString str, s;
+ long num;
+ int minX, maxX, minY, maxY, x, y;
+ XNODE* lNode;
+
+ lNode = FindNode( aNode, wxT( "padShapeType" ) );
+
+ if( lNode )
+ {
+ str = lNode->GetNodeContent();
+ str.Trim( false );
+ m_shape = str;
+ }
+
+ lNode = FindNode( aNode, wxT( "layerNumRef" ) );
+
+ if( lNode )
+ {
+ lNode->GetNodeContent().ToLong( &num );
+ m_PCadLayer = (int) num;
+ }
+
+ m_KiCadLayer = GetKiCadLayer();
+
+ if( m_shape == wxT( "Oval" )
+ || m_shape == wxT( "Rect" )
+ || m_shape == wxT( "Ellipse" )
+ || m_shape == wxT( "MtHole" )
+ || m_shape == wxT( "RndRect" ) )
+ {
+ lNode = FindNode( aNode, wxT( "shapeWidth" ) );
+
+ if( lNode )
+ SetWidth( lNode->GetNodeContent(), aDefaultMeasurementUnit, &m_width,
+ aActualConversion );
+
+ lNode = FindNode( aNode, wxT( "shapeHeight" ) );
+
+ if( lNode )
+ SetWidth(
+ lNode->GetNodeContent(), aDefaultMeasurementUnit, &m_height, aActualConversion );
+ }
+ else if( m_shape == wxT( "Polygon" ) )
+ {
+ // aproximation to simplier pad shape .....
+ lNode = FindNode( aNode, wxT( "shapeOutline" ) );
+
+ if( lNode )
+ lNode = FindNode( lNode, wxT( "pt" ) );
+
+ minX = 0;
+ maxX = 0;
+ minY = 0;
+ maxY = 0;
+
+ while( lNode )
+ {
+ s = lNode->GetNodeContent();
+ SetPosition( s, aDefaultMeasurementUnit, &x, &y, aActualConversion );
+
+ if( minX > x )
+ minX = x;
+
+ if( maxX < x )
+ maxX = x;
+
+ if( minY > y )
+ minY = y;
+
+ if( maxY < y )
+ maxY = y;
+
+ lNode = lNode->GetNext();
+ }
+
+ m_width = maxX - minX;
+ m_height = maxY - minY;
+ }
+}
+
+
+void PCB_PAD_SHAPE::AddToBoard()
+{
+}
+
+} // namespace PCAD2KICAD
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_pad_shape.h b/pcbnew/pcad2kicadpcb_plugin/pcb_pad_shape.h
new file mode 100644
index 0000000..662fb03
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_pad_shape.h
@@ -0,0 +1,61 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_pad_shape.h
+ */
+
+#ifndef PCB_PAD_SHAPE_H_
+#define PCB_PAD_SHAPE_H_
+
+#include <wx/wx.h>
+#include <wx/dynarray.h>
+
+#include <pcb_component.h>
+
+namespace PCAD2KICAD {
+
+class PCB_PAD_SHAPE : public PCB_COMPONENT
+{
+public:
+ wxString m_shape;
+ int m_width;
+ int m_height;
+
+ PCB_PAD_SHAPE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard );
+ ~PCB_PAD_SHAPE();
+
+ virtual void Parse( XNODE* aNode,
+ wxString aDefaultMeasurementUnit,
+ wxString aActualConversion );
+
+ void AddToBoard();
+};
+
+WX_DEFINE_ARRAY( PCB_PAD_SHAPE*, PCB_PAD_SHAPES_ARRAY );
+
+} // namespace PCAD2KICAD
+
+#endif // PCB_PAD_SHAPE_H_
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_plane.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_plane.cpp
new file mode 100644
index 0000000..be89e50
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_plane.cpp
@@ -0,0 +1,95 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008, 2012 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_plane.cpp
+ */
+
+#include <wx/wx.h>
+#include <wx/config.h>
+
+#include <common.h>
+
+#include <pcb_plane.h>
+
+namespace PCAD2KICAD {
+
+PCB_PLANE::PCB_PLANE( PCB_CALLBACKS* aCallbacks,
+ BOARD* aBoard,
+ int aPCadLayer ) :
+ PCB_POLYGON( aCallbacks, aBoard, aPCadLayer )
+{
+ m_priority = 1;
+}
+
+
+PCB_PLANE::~PCB_PLANE()
+{
+}
+
+
+bool PCB_PLANE::Parse( XNODE* aNode,
+ wxString aDefaultMeasurementUnit,
+ wxString aActualConversion,
+ wxStatusBar* aStatusBar )
+{
+ XNODE* lNode;
+ wxString pourType, str, propValue;
+
+ // aStatusBar->SetStatusText( aStatusBar->GetStatusText() + wxT( " Plane..." ) );
+
+ lNode = FindNode( aNode, wxT( "netNameRef" ) );
+
+ if( lNode )
+ {
+ lNode->GetAttribute( wxT( "Name" ), &propValue );
+ propValue.Trim( false );
+ propValue.Trim( true );
+ m_net = propValue;
+ m_netCode = GetNetCode( m_net );
+ }
+
+ if( FindNode( aNode, wxT( "width" ) ) )
+ SetWidth( FindNode( aNode, wxT( "width" ) )->GetNodeContent(),
+ aDefaultMeasurementUnit, &m_width, aActualConversion );
+
+ lNode = FindNode( aNode, wxT( "pcbPoly" ) );
+
+ if( lNode )
+ {
+ // retrieve plane outline
+ FormPolygon( lNode, &m_outline, aDefaultMeasurementUnit, aActualConversion );
+
+ m_positionX = m_outline[0]->x;
+ m_positionY = m_outline[0]->y;
+ }
+ else
+ {
+ return false;
+ }
+
+ return true;
+}
+
+} // namespace PCAD2KICAD
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_plane.h b/pcbnew/pcad2kicadpcb_plugin/pcb_plane.h
new file mode 100644
index 0000000..6ace28b
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_plane.h
@@ -0,0 +1,53 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008, 2012 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_plane.h
+ */
+
+#ifndef PCB_PLANE_H_
+#define PCB_PLANE_H_
+
+#include <wx/wx.h>
+
+#include <pcb_polygon.h>
+
+namespace PCAD2KICAD {
+
+class PCB_PLANE : public PCB_POLYGON
+{
+public:
+
+ PCB_PLANE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard, int aPCadLayer );
+ ~PCB_PLANE();
+
+ virtual bool Parse( XNODE* aNode,
+ wxString aDefaultMeasurementUnit,
+ wxString aActualConversion,
+ wxStatusBar* aStatusBar );
+};
+
+} // namespace PCAD2KICAD
+
+#endif // PCB_PLANE_H_
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.cpp
new file mode 100644
index 0000000..b3b4ec5
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.cpp
@@ -0,0 +1,253 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_polygon.cpp
+ */
+
+#include <wx/wx.h>
+#include <wx/config.h>
+
+#include <common.h>
+
+#include <pcb_polygon.h>
+
+namespace PCAD2KICAD {
+
+PCB_POLYGON::PCB_POLYGON( PCB_CALLBACKS* aCallbacks, BOARD* aBoard, int aPCadLayer ) :
+ PCB_COMPONENT( aCallbacks, aBoard )
+{
+ m_width = 0;
+ m_priority = 0;
+ m_objType = wxT( 'Z' );
+ m_PCadLayer = aPCadLayer;
+ m_KiCadLayer = GetKiCadLayer();
+ m_timestamp = GetNewTimestamp();
+ m_filled = true;
+}
+
+
+PCB_POLYGON::~PCB_POLYGON()
+{
+ int i, island;
+
+ for( i = 0; i < (int) m_outline.GetCount(); i++ )
+ {
+ delete m_outline[i];
+ }
+
+ for( island = 0; island < (int) m_cutouts.GetCount(); island++ )
+ {
+ for( i = 0; i < (int) m_cutouts[island]->GetCount(); i++ )
+ {
+ delete (*m_cutouts[island])[i];
+ }
+
+ delete m_cutouts[island];
+ }
+
+ for( island = 0; island < (int) m_islands.GetCount(); island++ )
+ {
+ for( i = 0; i < (int) m_islands[island]->GetCount(); i++ )
+ {
+ delete (*m_islands[island])[i];
+ }
+
+ delete m_islands[island];
+ }
+}
+
+void PCB_POLYGON::AssignNet( wxString aNetName )
+{
+ m_net = aNetName;
+ m_netCode = GetNetCode( m_net );
+}
+
+void PCB_POLYGON::SetOutline( VERTICES_ARRAY* aOutline )
+{
+ int i;
+
+ m_outline.Empty();
+
+ for( i = 0; i < (int) aOutline->GetCount(); i++ )
+ m_outline.Add( new wxRealPoint( (*aOutline)[i]->x, (*aOutline)[i]->y ) );
+
+ if( m_outline.Count() > 0 )
+ {
+ m_positionX = m_outline[0]->x;
+ m_positionY = m_outline[0]->y;
+ }
+}
+
+void PCB_POLYGON::FormPolygon( XNODE* aNode, VERTICES_ARRAY* aPolygon,
+ wxString aDefaultMeasurementUnit, wxString aActualConversion )
+{
+ XNODE* lNode;
+ double x, y;
+
+ lNode = FindNode( aNode, wxT( "pt" ) );
+
+ while( lNode )
+ {
+ if( lNode->GetName() == wxT( "pt" ) )
+ {
+ SetDoublePrecisionPosition(
+ lNode->GetNodeContent(), aDefaultMeasurementUnit, &x, &y, aActualConversion );
+ aPolygon->Add( new wxRealPoint( x, y ) );
+ }
+
+ lNode = lNode->GetNext();
+ }
+}
+
+
+bool PCB_POLYGON::Parse( XNODE* aNode,
+ wxString aDefaultMeasurementUnit,
+ wxString aActualConversion,
+ wxStatusBar* aStatusBar )
+{
+ XNODE* lNode;
+ wxString propValue;
+
+ // aStatusBar->SetStatusText( aStatusBar->GetStatusText() + wxT( " Polygon..." ) );
+
+ lNode = FindNode( aNode, wxT( "netNameRef" ) );
+
+ if( lNode )
+ {
+ lNode->GetAttribute( wxT( "Name" ), &propValue );
+ propValue.Trim( false );
+ propValue.Trim( true );
+ m_net = propValue;
+ m_netCode = GetNetCode( m_net );
+ }
+
+ // retrieve polygon outline
+ FormPolygon( aNode, &m_outline, aDefaultMeasurementUnit, aActualConversion );
+
+ m_positionX = m_outline[0]->x;
+ m_positionY = m_outline[0]->y;
+
+ // fill the polygon with the same contour as its outline is
+ m_islands.Add( new VERTICES_ARRAY );
+ FormPolygon( aNode, m_islands[0], aDefaultMeasurementUnit, aActualConversion );
+
+ return true;
+}
+
+
+void PCB_POLYGON::AddToModule( MODULE* aModule )
+{
+}
+
+
+void PCB_POLYGON::AddToBoard()
+{
+ int i = 0;
+
+ if( m_outline.GetCount() > 0 )
+ {
+ ZONE_CONTAINER* zone = new ZONE_CONTAINER( m_board );
+ m_board->Add( zone, ADD_APPEND );
+
+ zone->SetTimeStamp( m_timestamp );
+ zone->SetLayer( m_KiCadLayer );
+ zone->SetNetCode( m_netCode );
+
+ // add outline
+ int outline_hatch = CPolyLine::DIAGONAL_EDGE;
+
+ zone->Outline()->Start( m_KiCadLayer, KiROUND( m_outline[i]->x ),
+ KiROUND( m_outline[i]->y ), outline_hatch );
+
+ for( i = 1; i < (int) m_outline.GetCount(); i++ )
+ {
+ zone->AppendCorner( wxPoint( KiROUND( m_outline[i]->x ),
+ KiROUND( m_outline[i]->y ) ) );
+ }
+
+ zone->Outline()->CloseLastContour();
+
+ zone->SetZoneClearance( m_width );
+
+ zone->SetPriority( m_priority );
+
+ zone->Outline()->SetHatch( outline_hatch,
+ Mils2iu( zone->Outline()->GetDefaultHatchPitchMils() ),
+ true );
+
+ if ( m_objType == wxT( 'K' ) )
+ {
+ zone->SetIsKeepout( true );
+ zone->SetDoNotAllowTracks( true );
+ zone->SetDoNotAllowVias( true );
+ zone->SetDoNotAllowCopperPour( true );
+ }
+ else if( m_objType == wxT( 'C' ) )
+ {
+ // convert cutouts to keepouts because standalone cutouts are not supported in KiCad
+ zone->SetIsKeepout( true );
+ zone->SetDoNotAllowCopperPour( true );
+ }
+
+ //if( m_filled )
+ // cvpcb is not linked
+ // zone->BuildFilledPolysListData( m_board );
+ }
+}
+
+
+void PCB_POLYGON::SetPosOffset( int aX_offs, int aY_offs )
+{
+ int i, island;
+
+ PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs );
+
+ for( i = 0; i < (int) m_outline.GetCount(); i++ )
+ {
+ m_outline[i]->x += aX_offs;
+ m_outline[i]->y += aY_offs;
+ }
+
+ for( island = 0; island < (int) m_islands.GetCount(); island++ )
+ {
+ for( i = 0; i < (int) m_islands[island]->GetCount(); i++ )
+ {
+ (*m_islands[island])[i]->x += aX_offs;
+ (*m_islands[island])[i]->y += aY_offs;
+ }
+ }
+
+ for( island = 0; island < (int) m_cutouts.GetCount(); island++ )
+ {
+ for( i = 0; i < (int) m_cutouts[island]->GetCount(); i++ )
+ {
+ (*m_cutouts[island])[i]->x += aX_offs;
+ (*m_cutouts[island])[i]->y += aY_offs;
+ }
+ }
+}
+
+} // namespace PCAD2KICAD
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.h b/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.h
new file mode 100644
index 0000000..90ffdbd
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.h
@@ -0,0 +1,75 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_polygon.h
+ */
+
+#ifndef PCB_POLYGON_H_
+#define PCB_POLYGON_H_
+
+#include <wx/wx.h>
+
+#include <pcb_component.h>
+
+namespace PCAD2KICAD {
+
+//WX_DEFINE_ARRAY( wxRealPoint*, VERTICES_ARRAY );
+WX_DEFINE_ARRAY( VERTICES_ARRAY*, ISLANDS_ARRAY );
+
+class PCB_POLYGON : public PCB_COMPONENT
+{
+public:
+ int m_width;
+ int m_priority;
+ VERTICES_ARRAY m_outline; // collection of boundary/outline lines - objects
+ ISLANDS_ARRAY m_islands;
+ ISLANDS_ARRAY m_cutouts;
+
+ PCB_POLYGON( PCB_CALLBACKS* aCallbacks, BOARD* aBoard, int aPCadLayer );
+ ~PCB_POLYGON();
+
+ virtual bool Parse( XNODE* aNode,
+ wxString aDefaultMeasurementUnit,
+ wxString aActualConversion,
+ wxStatusBar* aStatusBar );
+
+ virtual void SetPosOffset( int aX_offs, int aY_offs );
+ void AddToModule( MODULE* aModule );
+ void AddToBoard();
+
+// protected:
+ void AssignNet( wxString aNetName );
+ void SetOutline( VERTICES_ARRAY* aOutline );
+
+ void FormPolygon( XNODE* aNode, VERTICES_ARRAY* aPolygon,
+ wxString aDefaultMeasurementUnit, wxString actualConversion );
+protected:
+ bool m_filled;
+};
+
+} // namespace PCAD2KICAD
+
+#endif // PCB_POLYGON_H_
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp
new file mode 100644
index 0000000..db8b57f
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_text.cpp
@@ -0,0 +1,138 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_text.cpp
+ */
+
+#include <wx/wx.h>
+#include <wx/config.h>
+
+#include <common.h>
+
+#include <pcb_text.h>
+
+namespace PCAD2KICAD {
+
+PCB_TEXT::PCB_TEXT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : PCB_COMPONENT( aCallbacks,
+ aBoard )
+{
+ m_objType = wxT( 'T' );
+}
+
+
+PCB_TEXT::~PCB_TEXT()
+{
+}
+
+
+void PCB_TEXT::Parse( XNODE* aNode,
+ int aLayer,
+ wxString aDefaultMeasurementUnit,
+ wxString aActualConversion )
+{
+ XNODE* lNode;
+ wxString str;
+
+ m_PCadLayer = aLayer;
+ m_KiCadLayer = GetKiCadLayer();
+ m_positionX = 0;
+ m_positionY = 0;
+ m_name.mirror = 0; // Normal, not mirrored
+ lNode = FindNode( aNode, wxT( "pt" ) );
+
+ if( lNode )
+ SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
+ &m_positionX, &m_positionY, aActualConversion );
+
+ lNode = FindNode( aNode, wxT( "rotation" ) );
+
+ if( lNode )
+ {
+ str = lNode->GetNodeContent();
+ str.Trim( false );
+ m_rotation = StrToInt1Units( str );
+ }
+
+ aNode->GetAttribute( wxT( "Name" ), &m_name.text );
+
+ str = FindNodeGetContent( aNode, wxT( "justify" ) );
+ m_name.justify = GetJustifyIdentificator( str );
+
+ str = FindNodeGetContent( aNode, wxT( "isFlipped" ) );
+
+ if( str == wxT( "True" ) )
+ m_name.mirror = 1;
+
+ lNode = FindNode( aNode, wxT( "textStyleRef" ) );
+
+ if( lNode )
+ SetFontProperty( lNode, &m_name, aDefaultMeasurementUnit, aActualConversion );
+}
+
+
+void PCB_TEXT::AddToModule( MODULE* aModule )
+{
+}
+
+
+void PCB_TEXT::AddToBoard()
+{
+ // Simple, not the best, but acceptable text positioning.
+ m_name.textPositionX = m_positionX;
+ m_name.textPositionY = m_positionY;
+ m_name.textRotation = m_rotation;
+ CorrectTextPosition( &m_name );
+
+ TEXTE_PCB* pcbtxt = new TEXTE_PCB( m_board );
+ m_board->Add( pcbtxt, ADD_APPEND );
+
+ pcbtxt->SetText( m_name.text );
+
+ pcbtxt->SetSize( wxSize( KiROUND( m_name.textHeight / 2 ),
+ KiROUND( m_name.textHeight / 1.1 ) ) );
+
+ pcbtxt->SetThickness( m_name.textstrokeWidth );
+ pcbtxt->SetOrientation( m_name.textRotation );
+
+ pcbtxt->SetTextPosition( wxPoint( m_name.correctedPositionX,
+ m_name.correctedPositionY ) );
+
+ pcbtxt->SetMirrored( m_name.mirror );
+ pcbtxt->SetTimeStamp( 0 );
+
+ pcbtxt->SetLayer( m_KiCadLayer );
+}
+
+
+// void PCB_TEXT::SetPosOffset( int aX_offs, int aY_offs )
+// {
+// PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs );
+
+// m_name.textPositionX += aX_offs;
+// m_name.textPositionY += aY_offs;
+// }
+
+} // namespace PCAD2KICAD
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_text.h b/pcbnew/pcad2kicadpcb_plugin/pcb_text.h
new file mode 100644
index 0000000..b85ec29
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_text.h
@@ -0,0 +1,59 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_text.h
+ */
+
+#ifndef PCB_TEXT_H_
+#define PCB_TEXT_H_
+
+#include <wx/wx.h>
+
+#include <pcb_component.h>
+
+namespace PCAD2KICAD {
+
+// Name property of parent is used for text value
+class PCB_TEXT : public PCB_COMPONENT
+{
+public:
+
+ PCB_TEXT( PCB_CALLBACKS* aCallbacks, BOARD* aBoard );
+ ~PCB_TEXT();
+
+ virtual void Parse( XNODE* aNode,
+ int aLayer,
+ wxString aDefaultMeasurementUnit,
+ wxString aActualConversion );
+ void AddToModule( MODULE* aModule );
+ void AddToBoard();
+
+// virtual void SetPosOffset( int aX_offs, int aY_offs );
+};
+
+} // namespace PCAD2KICAD
+
+#endif // PCB_TEXT_H_
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_via.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_via.cpp
new file mode 100644
index 0000000..49789d1
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_via.cpp
@@ -0,0 +1,139 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_via.cpp
+ */
+
+#include <wx/wx.h>
+#include <wx/config.h>
+
+#include <pcb_via.h>
+#include <pcb_via_shape.h>
+
+namespace PCAD2KICAD {
+
+PCB_VIA::PCB_VIA( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : PCB_PAD( aCallbacks, aBoard )
+{
+ m_objType = wxT( 'V' );
+}
+
+
+PCB_VIA::~PCB_VIA()
+{
+}
+
+
+void PCB_VIA::Parse( XNODE* aNode, wxString aDefaultMeasurementUnit,
+ wxString aActualConversion )
+{
+ XNODE* lNode, * tNode;
+ wxString propValue;
+ PCB_VIA_SHAPE* viaShape;
+
+ m_rotation = 0;
+ lNode = FindNode( aNode, wxT( "viaStyleRef" ) );
+
+ if( lNode )
+ {
+ lNode->GetAttribute( wxT( "Name" ), &propValue );
+ propValue.Trim( false );
+ propValue.Trim( true );
+ m_name.text = propValue;
+ }
+
+ lNode = FindNode( aNode, wxT( "pt" ) );
+
+ if( lNode )
+ SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
+ &m_positionX, &m_positionY, aActualConversion );
+
+ lNode = FindNode( aNode, wxT( "netNameRef" ) );
+
+ if( lNode )
+ {
+ lNode->GetAttribute( wxT( "Name" ), &propValue );
+ propValue.Trim( false );
+ propValue.Trim( true );
+ m_net = propValue;
+ m_netCode = GetNetCode( m_net );
+ }
+
+ lNode = aNode;
+
+ while( lNode && lNode->GetName() != wxT( "www.lura.sk" ) )
+ lNode = lNode->GetParent();
+
+ lNode = FindNode( lNode, wxT( "library" ) );
+
+ if ( !lNode )
+ THROW_IO_ERROR( wxT( "Unable to find library section" ) );
+
+ lNode = FindNode( lNode, wxT( "viaStyleDef" ) );
+
+ while( lNode )
+ {
+ lNode->GetAttribute( wxT( "Name" ), &propValue );
+
+ if( propValue.IsSameAs( m_name.text, false ) )
+ break;
+
+ lNode = lNode->GetNext();
+ }
+
+ if ( !lNode )
+ THROW_IO_ERROR( wxString::Format( wxT( "Unable to find viaStyleDef " ) + m_name.text ) );
+
+ if( lNode )
+ {
+ tNode = lNode;
+ lNode = FindNode( tNode, wxT( "holeDiam" ) );
+
+ if( lNode )
+ SetWidth( lNode->GetNodeContent(), aDefaultMeasurementUnit, &m_hole,
+ aActualConversion );
+
+ lNode = FindNode( tNode, wxT( "viaShape" ) );
+
+ while( lNode )
+ {
+ if( lNode->GetName() == wxT( "viaShape" ) )
+ {
+ // we support only Vias on specific layers......
+ // we do not support vias on "Plane", "NonSignal" , "Signal" ... layerr
+ if( FindNode( lNode, wxT( "layerNumRef" ) ) )
+ {
+ viaShape = new PCB_VIA_SHAPE( m_callbacks, m_board );
+ viaShape->Parse( lNode, aDefaultMeasurementUnit, aActualConversion );
+ m_shapes.Add( viaShape );
+ }
+ }
+
+ lNode = lNode->GetNext();
+ }
+ }
+}
+
+} // namespace PCAD2KICAD
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_via.h b/pcbnew/pcad2kicadpcb_plugin/pcb_via.h
new file mode 100644
index 0000000..05b5c3a
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_via.h
@@ -0,0 +1,54 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_via.h
+ */
+
+#ifndef PCB_VIA_H_
+#define PCB_VIA_H_
+
+#include <wx/wx.h>
+
+#include <pcb_pad.h>
+
+namespace PCAD2KICAD {
+
+// will be replaced by pad in next version ????
+class PCB_VIA : public PCB_PAD
+{
+public:
+
+ PCB_VIA( PCB_CALLBACKS* aCallbacks, BOARD* aBoard );
+ ~PCB_VIA();
+
+ virtual void Parse( XNODE* aNode,
+ wxString aDefaultMeasurementUnit,
+ wxString aActualConversion );
+};
+
+} // namespace PCAD2KICAD
+
+#endif // PCB_VIA_H_
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_via_shape.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_via_shape.cpp
new file mode 100644
index 0000000..70e6d60
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_via_shape.cpp
@@ -0,0 +1,88 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_via_shape.cpp
+ */
+
+#include <wx/wx.h>
+#include <wx/config.h>
+
+#include <common.h>
+
+#include <pcb_via_shape.h>
+
+namespace PCAD2KICAD {
+
+PCB_VIA_SHAPE::PCB_VIA_SHAPE( PCB_CALLBACKS* aCallbacks,
+ BOARD* aBoard ) : PCB_PAD_SHAPE( aCallbacks, aBoard )
+{
+}
+
+
+PCB_VIA_SHAPE::~PCB_VIA_SHAPE()
+{
+}
+
+
+void PCB_VIA_SHAPE::Parse( XNODE* aNode,
+ wxString aDefaultMeasurementUnit,
+ wxString aActualConversion )
+{
+ XNODE* lNode;
+ wxString str;
+ long num;
+
+ lNode = FindNode( aNode, wxT( "viaShapeType" ) );
+
+ if( lNode )
+ {
+ str = lNode->GetNodeContent();
+ str.Trim( false );
+ m_shape = str;
+ }
+
+ lNode = FindNode( aNode, wxT( "layerNumRef" ) );
+
+ if( lNode )
+ {
+ lNode->GetNodeContent().ToLong( &num );
+ m_PCadLayer = (int) num;
+ }
+
+ m_KiCadLayer = GetKiCadLayer();
+ lNode = FindNode( aNode, wxT( "shapeWidth" ) );
+
+ if( lNode )
+ SetWidth( lNode->GetNodeContent(), aDefaultMeasurementUnit, &m_width, aActualConversion );
+
+ lNode = FindNode( aNode, wxT( "shapeHeight" ) );
+
+ if( lNode )
+ SetWidth( lNode->GetNodeContent(), aDefaultMeasurementUnit, &m_height, aActualConversion );
+
+}
+
+} // namespace PCAD2KICAD
diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_via_shape.h b/pcbnew/pcad2kicadpcb_plugin/pcb_via_shape.h
new file mode 100644
index 0000000..d12fa62
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_via_shape.h
@@ -0,0 +1,52 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
+ * Copyright (C) 2007, 2008, 2012 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file pcb_via_shape.h
+ */
+
+#ifndef PCB_VIA_SHAPE_H_
+#define PCB_VIA_SHAPE_H_
+
+#include <wx/wx.h>
+
+#include <pcb_pad_shape.h>
+
+namespace PCAD2KICAD {
+
+class PCB_VIA_SHAPE : public PCB_PAD_SHAPE
+{
+public:
+ PCB_VIA_SHAPE( PCB_CALLBACKS* aCallbacks, BOARD* aBoard );
+ ~PCB_VIA_SHAPE();
+
+ virtual void Parse( XNODE* aNode,
+ wxString aDefaultMeasurementUnit,
+ wxString aActualConversion );
+};
+
+} // namespace PCAD2KICAD
+
+#endif // PCB_VIA_SHAPE_H_
diff --git a/pcbnew/pcad2kicadpcb_plugin/s_expr_loader.cpp b/pcbnew/pcad2kicadpcb_plugin/s_expr_loader.cpp
new file mode 100644
index 0000000..19ec21d
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/s_expr_loader.cpp
@@ -0,0 +1,116 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2012-2013 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file s_expr_loader.cpp
+ */
+
+#include <dsnlexer.h>
+#include <macros.h>
+#include <wx/xml/xml.h>
+#include <xnode.h>
+
+namespace PCAD2KICAD {
+
+static KEYWORD empty_keywords[1] = {};
+static const char ACCEL_ASCII_KEYWORD[] = "ACCEL_ASCII";
+
+void LoadInputFile( wxString aFileName, wxXmlDocument* aXmlDoc )
+{
+ char line[sizeof( ACCEL_ASCII_KEYWORD )];
+ int tok;
+ XNODE* iNode = NULL, *cNode = NULL;
+ wxString str, propValue, content;
+ wxCSConv conv( wxT( "windows-1251" ) );
+
+ FILE* fp = wxFopen( aFileName, wxT( "rt" ) );
+
+ if( !fp )
+ THROW_IO_ERROR( wxT( "Unable to open file: " ) + aFileName );
+
+ // check file format
+ if( !fgets( line, sizeof( line ), fp )
+ // first line starts with "ACCEL_ASCII" with optional stuff on same line after that.
+ || memcmp( line, ACCEL_ASCII_KEYWORD, sizeof(ACCEL_ASCII_KEYWORD)-1 ) )
+ THROW_IO_ERROR( "Unknown file type" );
+
+ // rewind the file
+ fseek( fp, 0, SEEK_SET );
+
+ // lexer now owns fp, will close on exception or return
+ DSNLEXER lexer( empty_keywords, 0, fp, aFileName );
+
+ iNode = new XNODE( wxXML_ELEMENT_NODE, wxT( "www.lura.sk" ) );
+
+ while( ( tok = lexer.NextTok() ) != DSN_EOF )
+ {
+ if( tok == DSN_RIGHT )
+ {
+ iNode = iNode->GetParent();
+ }
+ else if( tok == DSN_LEFT )
+ {
+ tok = lexer.NextTok();
+ str = wxEmptyString;
+ cNode = new XNODE( wxXML_ELEMENT_NODE, wxString( lexer.CurText(), conv ) );
+ iNode->AddChild( cNode );
+ iNode = cNode;
+ }
+ else if( cNode )
+ {
+ str = wxString( lexer.CurText(), conv );
+ if( tok == DSN_STRING )
+ {
+ // update attribute
+ if( iNode->GetAttribute( wxT( "Name" ), &propValue ) )
+ {
+ iNode->DeleteAttribute( wxT( "Name" ) );
+ iNode->AddAttribute( wxT( "Name" ), propValue + wxT( ' ' ) + str );
+ }
+ else
+ iNode->AddAttribute( wxT( "Name" ), str );
+ }
+ else if( str != wxEmptyString )
+ {
+ // update node content
+ content = cNode->GetNodeContent() + wxT( ' ' ) + str;
+
+ if( cNode->GetChildren() )
+ cNode->GetChildren()->SetContent( content );
+ else
+ cNode->AddChild( new wxXmlNode( wxXML_TEXT_NODE,
+ wxEmptyString,
+ content ) );
+ }
+ }
+ }
+
+ if( iNode )
+ {
+ aXmlDoc->SetRoot( iNode );
+ //aXmlDoc->Save( wxT( "test.xml" ) );
+ }
+}
+
+} // namespace PCAD2KICAD
diff --git a/pcbnew/pcad2kicadpcb_plugin/s_expr_loader.h b/pcbnew/pcad2kicadpcb_plugin/s_expr_loader.h
new file mode 100644
index 0000000..02c1857
--- /dev/null
+++ b/pcbnew/pcad2kicadpcb_plugin/s_expr_loader.h
@@ -0,0 +1,37 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2012 Alexander Lunev <al.lunev@yahoo.com>
+ * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/**
+ * @file s_expr_loader.h
+ */
+
+#ifndef S_EXPR_LOADER_H_
+#define S_EXPR_LOADER_H_
+
+namespace PCAD2KICAD
+{
+ void LoadInputFile( wxString aFileName, wxXmlDocument* aXmlDoc );
+}
+
+#endif // S_EXPR_LOADER_H_