Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kicad-source-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
kicad-source-mirror
Commits
e7cd29ec
Commit
e7cd29ec
authored
Nov 02, 2008
by
jerryjacobs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Beautify code for kicad.cpp, kicad/mainframe.cpp, treeprj_frame.cpp
parent
365dbe15
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
644 additions
and
360 deletions
+644
-360
kicad.cpp
kicad/kicad.cpp
+173
-63
mainframe.cpp
kicad/mainframe.cpp
+48
-42
treeprj_frame.cpp
kicad/treeprj_frame.cpp
+423
-255
No files found.
kicad/kicad.cpp
View file @
e7cd29ec
/********************************/
/* kicad.cpp - module principal */
/********************************/
/*****************************************************************************/
/**
* @file kicad.cpp
* @brief Main kicad library manager file
*/
/*****************************************************************************/
#ifdef __GNUG__
#pragma implementation
...
...
@@ -13,13 +18,9 @@
#include <wx/image.h>
//#define SPLASH_OK
#ifdef SPLASH_OK
/* Define Splash Image */
#ifdef USE_SPLASH_IMAGE
#define SPLASH_IMAGE logo_kicad.png
#include "wx/splash.h"
#include "wx/mediactrl.h"
#endif
...
...
@@ -35,95 +36,174 @@
#include <pyhandler.h>
#endif
/*
Routines exportee
s */
/*
Export function
s */
/*
fonctions importee
s */
/*
Import function
s */
char
*
GetFileName
(
char
*
FullPathName
);
void
ShowLogo
(
char
*
FonteFileName
);
/* Routines locales */
/************************************/
/* Called to initialize the program */
/************************************/
/* Local functions */
/************************************/
/* Called to initialize the program */
/************************************/
// Create a new application object
IMPLEMENT_APP
(
WinEDA_App
)
#ifdef KICAD_PYTHON
using
namespace
boost
::
python
;
/*****************************************************************************/
// Global functions:
/*****************************************************************************/
static
WinEDA_MainFrame
&
GetMainFrame
()
{
return
*
(
wxGetApp
().
m_MainFrame
);
}
static
void
WinEDAPrint
(
str
msg
)
{
GetMainFrame
().
PrintMsg
(
PyHandler
::
MakeStr
(
msg
)
+
wxT
(
"
\n
"
)
);
}
static
void
WinEDAClear
()
{
GetMainFrame
().
ClearMsg
();
}
static
object
GetTypeExt
(
enum
TreeFileType
type
)
{
return
PyHandler
::
Convert
(
WinEDA_PrjFrame
::
GetFileExt
(
type
)
);
}
/*****************************************************************************/
// WinEDA_MainFrame Special binding functions:
// (one line functions are simple wrappers)
/*****************************************************************************/
object
WinEDA_MainFrame
::
GetPrjName
()
const
{
return
PyHandler
::
Convert
(
m_PrjFileName
);
}
object
WinEDA_MainFrame
::
ToWx
()
{
return
object
(
handle
<>
(
borrowed
(
wxPyMake_wxObject
(
this
,
false
)
)
)
);
}
WinEDA_PrjFrame
*
WinEDA_MainFrame
::
GetTree
()
const
{
return
m_LeftWin
;
}
/**
* @brief TODO
*/
/*****************************************************************************/
void
WinEDA_MainFrame
::
AddFastLaunchPy
(
object
&
button
)
/*****************************************************************************/
{
wxBitmapButton
*
btn
;
bool
success
=
wxPyConvertSwigPtr
(
button
.
ptr
(),
(
void
**
)
&
btn
,
_T
(
"wxBitmapButton"
));
if
(
!
success
)
return
;
if
(
!
success
)
return
;
Py_INCREF
(
button
.
ptr
()
);
btn
->
Reparent
(
m_CommandWin
);
m_CommandWin
->
AddFastLaunch
(
btn
);
}
/*****************************************************************************/
// WinEDA_PrjFrame Special binding functions:
// (one line functions are simple wrappers)
/*****************************************************************************/
// TODO To WxWidgets ?
object
WinEDA_PrjFrame
::
ToWx
()
{
return
object
(
handle
<>
(
borrowed
(
wxPyMake_wxObject
(
this
,
false
)
)
)
);
}
// TODO Get ?
object
WinEDA_PrjFrame
::
GetFtExPy
(
enum
TreeFileType
type
)
const
{
return
PyHandler
::
Convert
(
GetFileExt
(
type
)
);
}
// Get python menu
object
WinEDA_PrjFrame
::
GetMenuPy
(
enum
TreeFileType
type
)
{
return
object
(
handle
<>
(
borrowed
(
wxPyMake_wxObject
(
GetContextMenu
(
(
int
)
type
),
false
)
)
)
);
}
// Get tree control
object
WinEDA_PrjFrame
::
GetTreeCtrl
()
{
return
object
(
handle
<>
(
borrowed
(
wxPyMake_wxObject
(
m_TreeProject
,
false
)
)
)
);
}
// Get current menu
object
WinEDA_PrjFrame
::
GetCurrentMenu
()
{
return
object
(
handle
<>
(
borrowed
(
wxPyMake_wxObject
(
m_PopupMenu
,
false
)
)
)
);
}
object
WinEDA_PrjFrame
::
ToWx
()
{
return
object
(
handle
<>
(
borrowed
(
wxPyMake_wxObject
(
this
,
false
)
)
)
);
}
object
WinEDA_PrjFrame
::
GetFtExPy
(
enum
TreeFileType
type
)
const
{
return
PyHandler
::
Convert
(
GetFileExt
(
type
)
);
}
object
WinEDA_PrjFrame
::
GetMenuPy
(
enum
TreeFileType
type
)
{
return
object
(
handle
<>
(
borrowed
(
wxPyMake_wxObject
(
GetContextMenu
(
(
int
)
type
),
false
)
)
)
);
}
object
WinEDA_PrjFrame
::
GetTreeCtrl
()
{
return
object
(
handle
<>
(
borrowed
(
wxPyMake_wxObject
(
m_TreeProject
,
false
)
)
)
);
}
object
WinEDA_PrjFrame
::
GetCurrentMenu
()
{
return
object
(
handle
<>
(
borrowed
(
wxPyMake_wxObject
(
m_PopupMenu
,
false
)
)
)
);
}
void
WinEDA_PrjFrame
::
NewFilePy
(
const
str
&
name
,
enum
TreeFileType
type
,
object
&
id
)
/**
* @brief TODO
*/
/*****************************************************************************/
void
WinEDA_PrjFrame
::
NewFilePy
(
const
str
&
name
,
enum
TreeFileType
type
,
object
&
id
)
/*****************************************************************************/
{
wxTreeItemId
root
;
if
(
!
wxPyConvertSwigPtr
(
id
.
ptr
(),
(
void
**
)
&
root
,
_T
(
"wxTreeItemId"
)
)
)
return
;
NewFile
(
PyHandler
::
MakeStr
(
name
),
type
,
root
);
}
/**
* @brief Add a file to the tree under root, or m_root if conversion is wrong
*/
/*****************************************************************************/
void
WinEDA_PrjFrame
::
AddFilePy
(
const
str
&
file
,
object
&
root
)
/*
Add a file to the tree under root, or m_root if conversion is wrong
*/
/*
***************************************************************************
*/
{
wxTreeItemId
*
theroot
=
&
m_root
;
if
(
!
wxPyConvertSwigPtr
(
root
.
ptr
(),
(
void
**
)
&
root
,
_T
(
"wxTreeItemId"
)
)
)
{
theroot
=
&
m_root
;
}
AddFile
(
PyHandler
::
MakeStr
(
file
),
*
theroot
);
}
/**
* @brief convert wxTreeItem into TreePrjItemData
*/
/*****************************************************************************/
TreePrjItemData
*
WinEDA_PrjFrame
::
GetItemData
(
const
object
&
item
)
/*
convert wxTreeItem into TreePrjItemData
*/
/*
***************************************************************************
*/
{
wxTreeItemId
*
id
=
NULL
;
if
(
!
wxPyConvertSwigPtr
(
item
.
ptr
(),
(
void
**
)
&
id
,
_T
(
"wxTreeItemId"
)
)
)
return
NULL
;
if
(
!
wxPyConvertSwigPtr
(
item
.
ptr
(),
(
void
**
)
&
id
,
_T
(
"wxTreeItemId"
)))
{
return
NULL
;
}
return
dynamic_cast
<
TreePrjItemData
*>
(
m_TreeProject
->
GetItemData
(
*
id
)
);
}
/*****************************************************************************/
// TreePrjItemData Special binding functions
// (one line functions are simple wrappers)
/*****************************************************************************/
// Python rename
bool
TreePrjItemData
::
RenamePy
(
const
str
&
newname
,
bool
check
)
{
return
Rename
(
PyHandler
::
MakeStr
(
newname
),
check
);
}
// Get python directory
object
TreePrjItemData
::
GetDirPy
()
const
{
return
PyHandler
::
Convert
(
GetDir
()
);
}
bool
TreePrjItemData
::
RenamePy
(
const
str
&
newname
,
bool
check
)
{
return
Rename
(
PyHandler
::
MakeStr
(
newname
),
check
);
}
object
TreePrjItemData
::
GetDirPy
()
const
{
return
PyHandler
::
Convert
(
GetDir
()
);
}
object
TreePrjItemData
::
GetFileNamePy
()
const
{
return
PyHandler
::
Convert
(
GetFileName
()
);
}
object
TreePrjItemData
::
GetMenuPy
()
{
return
object
(
handle
<>
(
borrowed
(
wxPyMake_wxObject
(
&
m_fileMenu
,
false
)
)
)
);
}
// Get python filename
object
TreePrjItemData
::
GetFileNamePy
()
const
{
return
PyHandler
::
Convert
(
GetFileName
()
);
}
// kicad module init function
// ( this function is called from PyHandler to init the kicad module )
// Get python menu
object
TreePrjItemData
::
GetMenuPy
()
{
return
object
(
handle
<>
(
borrowed
(
wxPyMake_wxObject
(
&
m_fileMenu
,
false
)
)
)
);
}
/**
* @brief KiCad python module init, \n
* This function is called from PyHandler to init the kicad module
*/
/*****************************************************************************/
static
void
py_kicad_init
()
/*****************************************************************************/
{
def
(
"GetMainFrame"
,
&
GetMainFrame
,
return_value_policy
<
reference_existing_object
>
()
);
def
(
"GetTypeExtension"
,
&
GetTypeExt
);
...
...
@@ -156,6 +236,7 @@ static void py_kicad_init()
.
value
(
"DIRECTORY"
,
TREE_DIRECTORY
)
.
value
(
"MAX"
,
TREE_MAX
);
class_
<
WinEDA_PrjFrame
>
(
"TreeWindow"
)
// wx Interface
.
def
(
"ToWx"
,
&
WinEDA_PrjFrame
::
ToWx
)
...
...
@@ -168,14 +249,38 @@ static void py_kicad_init()
.
def
(
"RemoveFilter"
,
&
WinEDA_PrjFrame
::
RemoveFilterPy
)
.
def
(
"GetFilters"
,
&
WinEDA_PrjFrame
::
GetFilters
,
return_value_policy
<
copy_const_reference
>
()
)
.
def
(
"GetCurrentMenu"
,
&
WinEDA_PrjFrame
::
GetCurrentMenu
)
// Project tree control
.
def
(
"AddState"
,
&
WinEDA_PrjFrame
::
AddStatePy
)
.
def
(
"GetTreeCtrl"
,
&
WinEDA_PrjFrame
::
GetTreeCtrl
)
.
def
(
"GetItemData"
,
&
WinEDA_PrjFrame
::
GetItemData
,
return_value_policy
<
reference_existing_object
>
()
)
.
def
(
"FindItemData"
,
&
WinEDA_PrjFrame
::
FindItemData
,
return_value_policy
<
reference_existing_object
>
()
)
.
def
(
"NewFile"
,
&
WinEDA_PrjFrame
::
NewFilePy
)
.
def
(
"AddFile"
,
&
WinEDA_PrjFrame
::
AddFilePy
)
;
/** Project tree control **/
// AddState
.
def
(
"AddState"
,
&
WinEDA_PrjFrame
::
AddStatePy
)
// GetTreeCtrl
.
def
(
"GetTreeCtrl"
,
&
WinEDA_PrjFrame
::
GetTreeCtrl
)
// GetItemData
.
def
(
"GetItemData"
,
&
WinEDA_PrjFrame
::
GetItemData
,
return_value_policy
<
reference_existing_object
>
()
)
// FindItemData
.
def
(
"FindItemData"
,
&
WinEDA_PrjFrame
::
FindItemData
,
return_value_policy
<
reference_existing_object
>
()
)
// NewFile
.
def
(
"NewFile"
,
&
WinEDA_PrjFrame
::
NewFilePy
)
// AddFile
.
def
(
"AddFile"
,
&
WinEDA_PrjFrame
::
AddFilePy
)
;
/* ENDOF class_<WinEDA_PrjFrame>( "TreeWindow" ) */
class_
<
WinEDA_MainFrame
>
(
"MainFrame"
)
// Wx interface
...
...
@@ -188,18 +293,25 @@ static void py_kicad_init()
}
// common module init function
/**
* @brief Common python module init
*/
/*****************************************************************************/
static
void
py_common_init
()
/*****************************************************************************/
{
def
(
"Print"
,
&
WinEDAPrint
);
def
(
"Clear"
,
&
WinEDAClear
);
}
#endif
/*****************************************************************************/
bool
WinEDA_App
::
OnInit
()
/*****************************************************************************/
{
wxImage
::
AddHandler
(
new
wxPNGHandler
);
...
...
@@ -236,8 +348,8 @@ bool WinEDA_App::OnInit()
m_MainFrame
->
m_LeftWin
->
ReCreateTreePrj
();
SetTopWindow
(
m_MainFrame
);
/* Splash
Screen L
ogo */
#ifdef
SPLASH_OK
/* Splash
screen l
ogo */
#ifdef
USE_SPLASH_IMAGE
wxString
logoname
(
wxString
(
m_BinDir
)
+
_T
(
"logokicad.png"
)
);
wxBitmap
splash_screen
;
if
(
splash_screen
.
LoadFile
(
logoname
,
wxBITMAP_TYPE_PNG
)
)
...
...
@@ -247,7 +359,7 @@ bool WinEDA_App::OnInit()
3000
,
m_MainFrame
,
wxID_ANY
,
wxDefaultPosition
,
wxDefaultSize
,
wxSIMPLE_BORDER
|
wxSTAY_ON_TOP
);
}
#endif
#endif
/* USE_SPLASH_IMAGE */
m_MainFrame
->
Show
(
TRUE
);
m_MainFrame
->
Raise
();
...
...
@@ -265,5 +377,3 @@ bool WinEDA_App::OnInit()
return
TRUE
;
}
// vim: tabstop=4 : noexpandtab :
kicad/mainframe.cpp
View file @
e7cd29ec
...
...
@@ -21,16 +21,19 @@
#include "kicad.h"
/****************/
/* Constructor */
/****************/
// Constructor
/*****************************************************************************/
WinEDA_MainFrame
::
WinEDA_MainFrame
(
WinEDA_App
*
eda_app
,
wxWindow
*
parent
,
const
wxString
&
title
,
const
wxPoint
&
pos
,
const
wxSize
&
size
)
:
WinEDA_BasicFrame
(
parent
,
KICAD_MAIN_FRAME
,
eda_app
,
title
,
pos
,
size
)
wxWindow
*
parent
,
const
wxString
&
title
,
const
wxPoint
&
pos
,
const
wxSize
&
size
)
:
WinEDA_BasicFrame
(
parent
,
KICAD_MAIN_FRAME
,
eda_app
,
title
,
pos
,
size
)
/*****************************************************************************/
{
wxString
msg
;
wxString
line
;
wxSize
clientsize
;
m_FrameName
=
wxT
(
"KicadFrame"
);
...
...
@@ -44,8 +47,10 @@ WinEDA_MainFrame::WinEDA_MainFrame( WinEDA_App* eda_app,
GetSettings
();
if
(
m_Parent
->
m_EDA_Config
)
{
m_Parent
->
m_EDA_Config
->
Read
(
wxT
(
"LeftWinWidth"
),
&
m_LeftWin_Width
);
m_Parent
->
m_EDA_Config
->
Read
(
wxT
(
"CommandWinWidth"
),
&
m_CommandWin_Height
);
m_Parent
->
m_EDA_Config
->
Read
(
wxT
(
"LeftWinWidth"
),
&
m_LeftWin_Width
);
m_Parent
->
m_EDA_Config
->
Read
(
wxT
(
"CommandWinWidth"
),
&
m_CommandWin_Height
);
}
SetSize
(
m_FramePos
.
x
,
m_FramePos
.
y
,
m_FrameSize
.
x
,
m_FrameSize
.
y
);
...
...
@@ -78,7 +83,7 @@ WinEDA_MainFrame::WinEDA_MainFrame( WinEDA_App* eda_app,
wxNO_BORDER
|
wxSW_3D
);
m_BottomWin
->
SetDefaultSize
(
wxSize
(
clientsize
.
x
,
150
)
);
m_BottomWin
->
SetOrientation
(
wxLAYOUT_HORIZONTAL
);
m_BottomWin
->
SetAlignment
(
wxLAYOUT_BOTTOM
);
m_BottomWin
->
SetAlignment
(
wxLAYOUT_BOTTOM
);
m_BottomWin
->
SetSashVisible
(
wxSASH_TOP
,
TRUE
);
m_BottomWin
->
SetSashVisible
(
wxSASH_LEFT
,
TRUE
);
m_BottomWin
->
SetExtraBorderSize
(
2
);
...
...
@@ -91,28 +96,27 @@ WinEDA_MainFrame::WinEDA_MainFrame( WinEDA_App* eda_app,
m_DialogWin
->
SetFont
(
*
g_StdFont
);
// m_CommandWin is the box with buttons which launch eechema, pcbnew ...
m_CommandWin
=
new
WinEDA_CommandFrame
(
this
,
ID_MAIN_COMMAND
,
m_CommandWin
=
new
WinEDA_CommandFrame
(
this
,
ID_MAIN_COMMAND
,
wxPoint
(
m_LeftWin_Width
,
0
),
wxSize
(
clientsize
.
x
,
m_CommandWin_Height
),
wxSize
(
clientsize
.
x
,
m_CommandWin_Height
),
wxNO_BORDER
|
wxSW_3D
);
wxString
line
;
msg
=
wxGetCwd
();
line
.
Printf
(
_
(
"Ready
\n
Working dir: %s
\n
"
),
msg
.
GetData
()
);
PrintMsg
(
line
);
#ifdef KICAD_PYTHON
#ifdef KICAD_PYTHON
PyHandler
::
GetInstance
()
->
DeclareEvent
(
wxT
(
"kicad::LoadProject"
)
);
#endif
#endif
}
/***************/
/* Destructor */
/***************/
/*****************************************************************************/
WinEDA_MainFrame
::~
WinEDA_MainFrame
()
/*****************************************************************************/
{
if
(
m_Parent
->
m_EDA_Config
)
{
...
...
@@ -127,7 +131,6 @@ WinEDA_MainFrame::~WinEDA_MainFrame()
/*******************************************************/
void
WinEDA_MainFrame
::
PrintMsg
(
const
wxString
&
text
)
/*******************************************************/
/*
* Put text in the dialog frame
*/
...
...
@@ -394,6 +397,7 @@ void WinEDA_MainFrame::OnRefresh( wxCommandEvent& event )
}
/*********************************/
void
WinEDA_MainFrame
::
ClearMsg
()
/*********************************/
...
...
@@ -401,11 +405,13 @@ void WinEDA_MainFrame::ClearMsg()
m_DialogWin
->
Clear
();
}
#ifdef KICAD_PYTHON
/*****************************************************************************/
void
WinEDA_MainFrame
::
OnRefreshPy
()
/*****************************************************************************/
{
m_LeftWin
->
ReCreateTreePrj
();
}
#endif
kicad/treeprj_frame.cpp
View file @
e7cd29ec
/*********************/
/* treeprj_frame.cpp */
/*********************/
/**
* @file treeprj_frame.cpp
* @brief TODO
*/
#ifdef KICAD_PYTHON
#include <pyhandler.h>
#include <pyhandler.h>
#endif
#include "fctsys.h"
...
...
@@ -45,30 +47,43 @@ const wxChar * s_AllowedExtensionsToList[] =
NULL
// end of list
};
/**
* @brief TODO
*/
/******************************************************************/
WinEDA_PrjFrame
::
WinEDA_PrjFrame
(
WinEDA_MainFrame
*
parent
,
const
wxPoint
&
pos
,
const
wxSize
&
size
)
:
wxSashLayoutWindow
(
parent
,
ID_LEFT_FRAME
,
pos
,
size
,
wxSashLayoutWindow
(
parent
,
ID_LEFT_FRAME
,
pos
,
size
,
wxNO_BORDER
|
wxSW_3D
)
/******************************************************************/
{
m_Parent
=
parent
;
m_TreeProject
=
NULL
;
wxMenu
*
menu
=
m_ContextMenus
[
TREE_PY
];
wxMenuItem
*
item
;
m_PopupMenu
=
NULL
;
/* Filtering is now inverted: the filters are actually used to _enable_ support
/*
* Filtering is now inverted: the filters are actually used to _enable_ support
* for a given file type.
*/
m_Filters
.
push_back
(
wxT
(
"^.*
\\
.sch$"
)
);
// note: sch filter must be first because of a test in AddFile() below
// NOTE: sch filter must be first because of a test in AddFile() below
m_Filters
.
push_back
(
wxT
(
"^.*
\\
.sch$"
)
);
for
(
int
ii
=
0
;
s_AllowedExtensionsToList
[
ii
]
!=
NULL
;
ii
++
)
{
m_Filters
.
push_back
(
s_AllowedExtensionsToList
[
ii
]
);
}
m_Filters
.
push_back
(
wxT
(
"^no kicad files found"
)
);
#ifdef KICAD_PYTHON
#ifdef KICAD_PYTHON
m_Filters
.
push_back
(
wxT
(
"^.*
\\
.py$"
)
);
PyHandler
::
GetInstance
()
->
DeclareEvent
(
wxT
(
"kicad::RunScript"
)
);
...
...
@@ -80,31 +95,32 @@ WinEDA_PrjFrame::WinEDA_PrjFrame( WinEDA_MainFrame* parent,
PyHandler
::
GetInstance
()
->
DeclareEvent
(
wxT
(
"kicad::DeleteFile"
)
);
PyHandler
::
GetInstance
()
->
DeclareEvent
(
wxT
(
"kicad::RenameFile"
)
);
PyHandler
::
GetInstance
()
->
DeclareEvent
(
wxT
(
"kicad::MoveFile"
)
);
#endif
#endif
/* KICAD_PYTHON */
for
(
int
i
=
0
;
i
<
TREE_MAX
;
i
++
)
m_ContextMenus
.
push_back
(
new
wxMenu
()
);
// Python script context menu:
wxMenu
*
menu
=
m_ContextMenus
[
TREE_PY
];
#ifdef KICAD_PYTHON
// Python script context menu
#ifdef KICAD_PYTHON
item
=
new
wxMenuItem
(
menu
,
ID_PROJECT_RUNPY
,
_
(
"&Run"
),
_
(
"Run the Python Script"
)
);
item
->
SetBitmap
(
icon_python_small_xpm
);
menu
->
Append
(
item
);
#endif
#endif
/* KICAD_PYTHON */
item
=
new
wxMenuItem
(
menu
,
ID_PROJECT_TXTEDIT
,
// ID_PROJECT_TXTEDIT
item
=
new
wxMenuItem
(
menu
,
ID_PROJECT_TXTEDIT
,
_
(
"&Edit in a text editor"
),
_
(
"&Open the file in a Text Editor"
)
);
item
->
SetBitmap
(
icon_txt_xpm
);
menu
->
Append
(
item
);
// New files context menu:
wxMenu
*
menus
[
2
];
menus
[
0
]
=
m_ContextMenus
[
TREE_DIRECTORY
];
...
...
@@ -114,56 +130,80 @@ WinEDA_PrjFrame::WinEDA_PrjFrame( WinEDA_MainFrame* parent,
{
menu
=
menus
[
i
];
item
=
new
wxMenuItem
(
menu
,
ID_PROJECT_NEWDIR
,
_
(
"New D&irectory"
),
_
(
"Create a New Directory"
)
);
// ID_PROJECT_NEWDIR
item
=
new
wxMenuItem
(
menu
,
ID_PROJECT_NEWDIR
,
_
(
"New D&irectory"
),
_
(
"Create a New Directory"
)
);
item
->
SetBitmap
(
directory_xpm
);
menu
->
Append
(
item
);
#ifdef KICAD_PYTHON
item
=
new
wxMenuItem
(
menu
,
ID_PROJECT_NEWPY
,
_
(
"New P&ython Script"
),
_
(
"Create a New Python Script"
)
);
// ID_PROJECT_NEWPY
#ifdef KICAD_PYTHON
item
=
new
wxMenuItem
(
menu
,
ID_PROJECT_NEWPY
,
_
(
"New P&ython Script"
),
_
(
"Create a New Python Script"
)
);
item
->
SetBitmap
(
new_python_xpm
);
menu
->
Append
(
item
);
#endif
#endif
/* KICAD_PYTHON */
item
=
new
wxMenuItem
(
menu
,
ID_PROJECT_NEWTXT
,
_
(
"New &Text File"
),
_
(
"Create a New Txt File"
)
);
// ID_PROJECT_NEWTXT
item
=
new
wxMenuItem
(
menu
,
ID_PROJECT_NEWTXT
,
_
(
"New &Text File"
),
_
(
"Create a New Txt File"
)
);
item
->
SetBitmap
(
new_txt_xpm
);
menu
->
Append
(
item
);
item
=
new
wxMenuItem
(
menu
,
ID_PROJECT_NEWFILE
,
_
(
"New &File"
),
_
(
"Create a New File"
)
);
// ID_PROJECT_NEWFILE
item
=
new
wxMenuItem
(
menu
,
ID_PROJECT_NEWFILE
,
_
(
"New &File"
),
_
(
"Create a New File"
)
);
item
->
SetBitmap
(
new_xpm
);
menu
->
Append
(
item
);
}
// Put the Rename and Delete file menu commands:
for
(
int
i
=
TREE_PROJECT
+
1
;
i
<
TREE_MAX
;
i
++
)
{
menu
=
m_ContextMenus
[
i
];
item
=
new
wxMenuItem
(
menu
,
ID_PROJECT_RENAME
,
TREE_DIRECTORY
!=
i
?
_
(
"&Rename file"
)
:
_
(
"&Rename directory"
),
TREE_DIRECTORY
!=
i
?
_
(
"Rename file"
)
:
_
(
"&Rename directory"
)
);
// ID_PROJECT_RENAME
item
=
new
wxMenuItem
(
menu
,
ID_PROJECT_RENAME
,
TREE_DIRECTORY
!=
i
?
_
(
"&Rename file"
)
:
_
(
"&Rename directory"
),
TREE_DIRECTORY
!=
i
?
_
(
"Rename file"
)
:
_
(
"&Rename directory"
)
);
item
->
SetBitmap
(
right_xpm
);
menu
->
Append
(
item
);
if
(
TREE_DIRECTORY
!=
i
)
{
item
=
new
wxMenuItem
(
menu
,
ID_PROJECT_TXTEDIT
,
// ID_PROJECT_TXTEDIT
item
=
new
wxMenuItem
(
menu
,
ID_PROJECT_TXTEDIT
,
_
(
"&Edit in a text editor"
),
_
(
"Open the file in a Text Editor"
)
);
item
->
SetBitmap
(
icon_txt_xpm
);
menu
->
Append
(
item
);
}
item
=
new
wxMenuItem
(
menu
,
ID_PROJECT_DELETE
,
TREE_DIRECTORY
!=
i
?
_
(
"&Delete File"
)
:
_
(
"&Delete Directory"
),
TREE_DIRECTORY
!=
i
?
_
(
"Delete the File"
)
:
_
(
"&Delete the Directory and its content"
)
);
// ID_PROJECT_DELETE
item
=
new
wxMenuItem
(
menu
,
ID_PROJECT_DELETE
,
TREE_DIRECTORY
!=
i
?
_
(
"&Delete File"
)
:
_
(
"&Delete Directory"
),
TREE_DIRECTORY
!=
i
?
_
(
"Delete the File"
)
:
_
(
"&Delete the Directory and its content"
)
);
item
->
SetBitmap
(
delete_xpm
);
menu
->
Append
(
item
);
}
...
...
@@ -172,7 +212,10 @@ WinEDA_PrjFrame::WinEDA_PrjFrame( WinEDA_MainFrame* parent,
}
/*****************************************************************************/
BEGIN_EVENT_TABLE
(
WinEDA_PrjFrame
,
wxSashLayoutWindow
)
/*****************************************************************************/
EVT_TREE_BEGIN_LABEL_EDIT
(
ID_PROJECT_TREE
,
WinEDA_PrjFrame
::
OnRenameAsk
)
EVT_TREE_END_LABEL_EDIT
(
ID_PROJECT_TREE
,
WinEDA_PrjFrame
::
OnRename
)
...
...
@@ -188,25 +231,35 @@ EVT_MENU( ID_PROJECT_NEWTXT, WinEDA_PrjFrame::OnNewTxtFile )
EVT_MENU
(
ID_PROJECT_DELETE
,
WinEDA_PrjFrame
::
OnDeleteFile
)
EVT_MENU
(
ID_PROJECT_RENAME
,
WinEDA_PrjFrame
::
OnRenameFile
)
#ifdef KICAD_PYTHON
EVT_MENU
(
ID_PROJECT_RUNPY
,
WinEDA_PrjFrame
::
OnRunPy
)
#endif
EVT_MENU
(
ID_PROJECT_RUNPY
,
WinEDA_PrjFrame
::
OnRunPy
)
#endif
/* KICAD_PYTHON */
/*****************************************************************************/
END_EVENT_TABLE
()
/*****************************************************************************/
/********************************/
/*****************************************************************************/
WinEDA_TreePrj
::~
WinEDA_TreePrj
()
/********************************/
/********************************
*********************************************
/
{
}
/*******************************************************/
void
WinEDA_PrjFrame
::
OnDragStart
(
wxTreeEvent
&
event
)
/*******************************************************/
// Allowing drag&drop of file other than the currently opened project
/**
* @brief Allowing drag & drop of file other than the currently opened project
*/
/*****************************************************************************/
void
WinEDA_PrjFrame
::
OnDragStart
(
wxTreeEvent
&
event
)
/*****************************************************************************/
{
/* Ensure item is selected (Under Windows start drag does not activate the item) */
/* Ensure item is selected
(Under Windows start drag does not activate the item) */
wxTreeItemId
curr_item
=
event
.
GetItem
();
m_TreeProject
->
SelectItem
(
curr_item
);
...
...
@@ -224,9 +277,10 @@ void WinEDA_PrjFrame::OnDragStart( wxTreeEvent& event )
}
/*******************************************************/
/*****************************************************************************/
void
WinEDA_PrjFrame
::
OnDragEnd
(
wxTreeEvent
&
event
)
/*******************************************************/
/*******************************************************
**********************
/
{
m_Parent
->
SetCursor
(
wxNullCursor
);
...
...
@@ -261,17 +315,18 @@ void WinEDA_PrjFrame::OnDragEnd( wxTreeEvent& event )
}
/************************************/
/*****************************************************************************/
void
WinEDA_PrjFrame
::
ClearFilters
()
/************************************/
/************************************
*****************************************
/
{
m_Filters
.
clear
();
}
/*************************************************************/
/*************************************************************
****************
/
void
WinEDA_PrjFrame
::
RemoveFilter
(
const
wxString
&
filter
)
/*************************************************************/
/*************************************************************
****************
/
{
for
(
unsigned
int
i
=
0
;
i
<
m_Filters
.
size
();
i
++
)
{
...
...
@@ -284,13 +339,17 @@ void WinEDA_PrjFrame::RemoveFilter( const wxString& filter )
}
#ifdef KICAD_PYTHON
/********************************************************************************/
TreePrjItemData
*
WinEDA_PrjFrame
::
FindItemData
(
const
boost
::
python
::
str
&
name
)
/********************************************************************************/
// Return the data corresponding to the file, or NULL
/**
* @brief Return the data corresponding to the file, or NULL
*/
/*****************************************************************************/
TreePrjItemData
*
WinEDA_PrjFrame
::
FindItemData
(
const
boost
::
python
::
str
&
name
)
/*****************************************************************************/
{
// (Interative tree parsing)
std
::
vector
<
wxTreeItemId
>
roots1
,
roots2
;
...
...
@@ -349,17 +408,25 @@ TreePrjItemData* WinEDA_PrjFrame::FindItemData( const boost::python::str& name )
}
/******************************************************************/
void
WinEDA_PrjFrame
::
RemoveFilterPy
(
const
boost
::
python
::
str
&
filter
)
/******************************************************************/
/**
* @brief TODO
*/
/*****************************************************************************/
void
WinEDA_PrjFrame
::
RemoveFilterPy
(
const
boost
::
python
::
str
&
filter
)
/*****************************************************************************/
{
RemoveFilter
(
PyHandler
::
MakeStr
(
filter
)
);
}
/******************************************************************/
/**
* @brief TODO
*/
/*****************************************************************************/
void
WinEDA_PrjFrame
::
AddFilter
(
const
boost
::
python
::
str
&
filter
)
/******************************************************************/
/******************************************************************
***********
/
{
wxRegEx
reg
;
wxString
text
=
PyHandler
::
MakeStr
(
filter
);
...
...
@@ -369,44 +436,88 @@ void WinEDA_PrjFrame::AddFilter( const boost::python::str& filter )
m_Filters
.
push_back
(
text
);
}
#endif
#endif
/* KICAD_PYTHON */
/******************************************************************/
/**
* @brief TODO
*/
/*****************************************************************************/
const
std
::
vector
<
wxString
>&
WinEDA_PrjFrame
::
GetFilters
()
/******************************************************************/
/******************************************************************
***********
/
{
return
m_Filters
;
}
/******************************************************************/
/**
* @brief TODO
*/
/*****************************************************************************/
wxMenu
*
WinEDA_PrjFrame
::
GetContextMenu
(
int
type
)
/******************************************************************/
/******************************************************************
***********
/
{
return
m_ContextMenus
[
type
];
}
/**
* @brief TODO
*/
/*****************************************************************************/
void
WinEDA_PrjFrame
::
OnNewDirectory
(
wxCommandEvent
&
event
)
/*****************************************************************************/
{
NewFile
(
TREE_DIRECTORY
);
}
/**
* @brief TODO
*/
/*****************************************************************************/
void
WinEDA_PrjFrame
::
OnNewFile
(
wxCommandEvent
&
event
)
/*****************************************************************************/
{
NewFile
(
TREE_UNKNOWN
);
}
/**
* @brief TODO
*/
/*****************************************************************************/
void
WinEDA_PrjFrame
::
OnNewPyFile
(
wxCommandEvent
&
event
)
/*****************************************************************************/
{
NewFile
(
TREE_PY
);
}
/**
* @brief TODO
*/
/*****************************************************************************/
void
WinEDA_PrjFrame
::
OnNewTxtFile
(
wxCommandEvent
&
event
)
/*****************************************************************************/
{
NewFile
(
TREE_TXT
);
}
/******************************************************************/
/**
* @brief TODO
*/
/*****************************************************************************/
void
WinEDA_PrjFrame
::
NewFile
(
TreeFileType
type
)
/******************************************************************/
/******************************************************************
***********
/
{
wxString
filename
;
wxString
mask
=
GetFileExt
(
type
);
...
...
@@ -418,6 +529,7 @@ void WinEDA_PrjFrame::NewFile( TreeFileType type )
TreePrjItemData
*
treeData
;
wxString
FullFileName
;
treeData
=
GetSelectedData
();
if
(
!
treeData
)
return
;
...
...
@@ -425,7 +537,6 @@ void WinEDA_PrjFrame::NewFile( TreeFileType type )
dir
=
treeData
->
GetDir
();
// Ask for the new file name
filename
=
EDA_FileSelector
(
TREE_DIRECTORY
!=
type
?
_
(
"Create New File:"
)
:
_
(
"Create New Directory"
),
wxGetCwd
()
+
sep
+
dir
,
/* Chemin par defaut */
...
...
@@ -449,6 +560,7 @@ void WinEDA_PrjFrame::NewFile( TreeFileType type )
else
{
root
=
m_TreeProject
->
GetItemParent
(
m_TreeProject
->
GetSelection
()
);
if
(
!
root
.
IsOk
()
)
root
=
m_TreeProject
->
GetSelection
();
}
...
...
@@ -457,42 +569,53 @@ void WinEDA_PrjFrame::NewFile( TreeFileType type )
}
/******************************************************************/
/**
* @brief TODO
*/
/*****************************************************************************/
void
WinEDA_PrjFrame
::
NewFile
(
const
wxString
&
name
,
TreeFileType
type
,
wxTreeItemId
&
root
)
/******************************************************************/
TreeFileType
type
,
wxTreeItemId
&
root
)
/*****************************************************************************/
{
if
(
TREE_DIRECTORY
!=
type
)
{
wxFile
(
name
,
wxFile
::
write
);
#ifdef KICAD_PYTHON
PyHandler
::
GetInstance
()
->
TriggerEvent
(
wxT
(
"kicad::NewFile"
),
PyHandler
::
Convert
(
name
)
);
#endif
#ifdef KICAD_PYTHON
PyHandler
::
GetInstance
()
->
TriggerEvent
(
wxT
(
"kicad::NewFile"
),
PyHandler
::
Convert
(
name
)
);
#endif
/* KICAD_PYTHON */
}
else
{
wxMkdir
(
name
);
#ifdef KICAD_PYTHON
PyHandler
::
GetInstance
()
->
TriggerEvent
(
wxT
(
"kicad::NewDirectory"
),
PyHandler
::
Convert
(
name
)
);
#endif
#ifdef KICAD_PYTHON
PyHandler
::
GetInstance
()
->
TriggerEvent
(
wxT
(
"kicad::NewDirectory"
),
PyHandler
::
Convert
(
name
)
);
#endif
/* KICAD_PYTHON */
}
AddFile
(
name
,
root
);
}
/******************************************************************/
/**
* @brief TODO
*/
/*****************************************************************************/
wxString
WinEDA_PrjFrame
::
GetFileExt
(
TreeFileType
type
)
/******************************************************************/
/******************************************************************
***********
/
{
wxString
ext
;
switch
(
type
)
{
case
0
:
break
;
// 0 is not used
case
0
:
// 0 is not used
break
;
case
TREE_PROJECT
:
ext
=
wxT
(
".pro"
);
...
...
@@ -534,13 +657,15 @@ wxString WinEDA_PrjFrame::GetFileExt( TreeFileType type )
}
/**************************************************************************/
bool
WinEDA_PrjFrame
::
AddFile
(
const
wxString
&
name
,
wxTreeItemId
&
root
)
/**************************************************************************/
/* add filename "name" to the tree
/**
* @brief Add filename "name" to the tree \n
* if name is a directory, add the sub directory file names
* @return TODO
*/
/*****************************************************************************/
bool
WinEDA_PrjFrame
::
AddFile
(
const
wxString
&
name
,
wxTreeItemId
&
root
)
/*****************************************************************************/
{
wxTreeItemId
cellule
;
...
...
@@ -586,8 +711,7 @@ bool WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root )
fp
=
wxFopen
(
FullFileName
,
wxT
(
"rt"
)
);
if
(
fp
==
NULL
)
{
//printf("Unable to open \"%s\"\n", (const char*) FullFileName.mb_str() );
return
false
;
// why show a file we cannot open?
return
false
;
}
addFile
=
false
;
...
...
@@ -640,8 +764,8 @@ bool WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root )
}
kid
=
m_TreeProject
->
GetNextChild
(
root
,
cookie
);
}
// Append the item (only appending the filename not the full path):
// Append the item (only appending the filename not the full path):
wxString
file
=
wxFileNameFromPath
(
name
);
cellule
=
m_TreeProject
->
AppendItem
(
root
,
file
);
TreePrjItemData
*
data
=
new
TreePrjItemData
(
type
,
name
,
m_TreeProject
);
...
...
@@ -659,41 +783,49 @@ bool WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root )
else
data
->
m_IsRootFile
=
false
;
#ifdef KICAD_PYTHON
PyHandler
::
GetInstance
()
->
TriggerEvent
(
wxT
(
"kicad::TreeAddFile"
),
PyHandler
::
Convert
(
name
)
);
#endif
#ifdef ADD_FILES_IN_SUBDIRS
#ifdef KICAD_PYTHON
PyHandler
::
GetInstance
()
->
TriggerEvent
(
wxT
(
"kicad::TreeAddFile"
),
PyHandler
::
Convert
(
name
)
);
#endif
/* KICAD_YTHON */
// When enabled This section adds dirs and files found in the subdirs
// in this case AddFile is recursive.
#ifdef ADD_FILES_IN_SUBDIRS
if
(
TREE_DIRECTORY
==
type
)
{
const
wxString
sep
=
wxFileName
().
GetPathSeparator
();
wxDir
dir
(
name
);
wxString
dir_filename
;
if
(
dir
.
GetFirst
(
&
dir_filename
)
)
{
do
{
AddFile
(
name
+
sep
+
dir_filename
,
cellule
);
}
while
(
dir
.
GetNext
(
&
dir_filename
)
);
}
while
(
dir
.
GetNext
(
&
dir_filename
)
);
}
/* Sort filenames by alphabetic order */
m_TreeProject
->
SortChildren
(
cellule
);
}
#endif
#endif
/* ADD_FILES_IN_SUBDIRS */
return
true
;
}
/******************************************/
void
WinEDA_PrjFrame
::
ReCreateTreePrj
()
/******************************************/
/* Create or modify the tree showing project file names
/**
* @brief Create or modify the tree showing project file names
* @return TODO
*/
/*****************************************************************************/
void
WinEDA_PrjFrame
::
ReCreateTreePrj
()
/*****************************************************************************/
{
wxTreeItemId
rootcellule
;
wxString
Text
;
...
...
@@ -760,11 +892,13 @@ void WinEDA_PrjFrame::ReCreateTreePrj()
}
/**************************************************/
void
WinEDA_PrjFrame
::
OnRight
(
wxTreeEvent
&
Event
)
/**************************************************/
// Opens (popup) the context menu
/**
* @brief Opens *popup* the context menu
*/
/*****************************************************************************/
void
WinEDA_PrjFrame
::
OnRight
(
wxTreeEvent
&
Event
)
/*****************************************************************************/
{
int
tree_id
;
TreePrjItemData
*
tree_data
;
...
...
@@ -819,19 +953,25 @@ void WinEDA_PrjFrame::OnRight( wxTreeEvent& Event )
// At last, call python to let python add menu items "on the fly"
#ifdef KICAD_PYTHON
#ifdef KICAD_PYTHON
PyHandler
::
GetInstance
()
->
TriggerEvent
(
wxT
(
"kicad::TreeContextMenu"
),
PyHandler
::
Convert
(
FullFileName
)
);
#endif
#endif
/* KICAD_PYTHON */
if
(
m_PopupMenu
)
PopupMenu
(
m_PopupMenu
);
}
/*******************************************************/
/**
* @brief TODO
*/
/*****************************************************************************/
void
WinEDA_PrjFrame
::
OnTxtEdit
(
wxCommandEvent
&
event
)
/*******************************************************/
/*******************************************************
**********************
/
{
TreePrjItemData
*
tree_data
=
GetSelectedData
();
...
...
@@ -841,20 +981,27 @@ void WinEDA_PrjFrame::OnTxtEdit( wxCommandEvent& event )
wxString
FullFileName
=
tree_data
->
GetFileName
();
AddDelimiterString
(
FullFileName
);
wxString
editorname
=
GetEditorName
();
if
(
!
editorname
.
IsEmpty
()
)
{
#ifdef KICAD_PYTHON
#ifdef KICAD_PYTHON
PyHandler
::
GetInstance
()
->
TriggerEvent
(
wxT
(
"kicad::EditScript"
),
PyHandler
::
Convert
(
FullFileName
)
);
#endif
#endif
ExecuteFile
(
this
,
editorname
,
FullFileName
);
}
}
/***************************************************/
/**
* @brief TODO
*/
/*****************************************************************************/
void
WinEDA_PrjFrame
::
OnDeleteFile
(
wxCommandEvent
&
)
/***************************************************/
/***************************************************
**************************
/
{
TreePrjItemData
*
tree_data
=
GetSelectedData
();
...
...
@@ -864,9 +1011,13 @@ void WinEDA_PrjFrame::OnDeleteFile( wxCommandEvent& )
}
/***************************************************/
/**
* @brief TODO
*/
/*****************************************************************************/
void
WinEDA_PrjFrame
::
OnRenameFile
(
wxCommandEvent
&
)
/***************************************************/
/***************************************************
**************************
/
{
wxTreeItemId
curr_item
=
m_TreeProject
->
GetSelection
();
TreePrjItemData
*
tree_data
=
GetSelectedData
();
...
...
@@ -876,20 +1027,24 @@ void WinEDA_PrjFrame::OnRenameFile( wxCommandEvent& )
wxString
buffer
=
m_TreeProject
->
GetItemText
(
curr_item
);
wxString
msg
=
_
(
"Change filename: "
)
+
tree_data
->
m_FileName
;
if
(
Get_Message
(
msg
,
_
(
"Change filename"
),
buffer
,
this
)
!=
0
)
return
;
//Abort command
if
(
tree_data
->
Rename
(
buffer
,
true
)
)
{
m_TreeProject
->
SetItemText
(
curr_item
,
buffer
);
}
}
#ifdef KICAD_PYTHON
/***************************************************/
/**
* @brief TODO
*/
/*****************************************************************************/
void
WinEDA_PrjFrame
::
OnRunPy
(
wxCommandEvent
&
event
)
/***************************************************/
/***************************************************
**************************
/
{
TreePrjItemData
*
tree_data
=
GetSelectedData
();
...
...
@@ -903,14 +1058,17 @@ void WinEDA_PrjFrame::OnRunPy( wxCommandEvent& event )
}
/****************************************************************/
int
WinEDA_PrjFrame
::
AddStatePy
(
boost
::
python
::
object
&
bitmap
)
/****************************************************************/
// Add a state to the image list ...
/**
* @brief Add a state to the image list
*/
/*****************************************************************************/
int
WinEDA_PrjFrame
::
AddStatePy
(
boost
::
python
::
object
&
bitmap
)
/*****************************************************************************/
{
wxBitmap
*
image
;
bool
success
=
wxPyConvertSwigPtr
(
bitmap
.
ptr
(),
(
void
**
)
&
image
,
_T
(
"wxBitmap"
)
);
bool
success
=
wxPyConvertSwigPtr
(
bitmap
.
ptr
(),
(
void
**
)
&
image
,
_T
(
"wxBitmap"
)
);
if
(
!
success
)
return
-
1
;
...
...
@@ -931,13 +1089,16 @@ int WinEDA_PrjFrame::AddStatePy( boost::python::object& bitmap )
return
ret
;
}
#endif
/* KICAD_PYTHON */
#endif
/***************************************************/
/**
* @brief Prevent the main project to be renamed
*/
/*****************************************************************************/
void
WinEDA_PrjFrame
::
OnRenameAsk
(
wxTreeEvent
&
event
)
/***************************************************/
/* Prevent the main project to be renamed */
/*****************************************************************************/
{
TreePrjItemData
*
tree_data
=
GetSelectedData
();
...
...
@@ -948,10 +1109,13 @@ void WinEDA_PrjFrame::OnRenameAsk( wxTreeEvent& event )
}
/***************************************************/
/**
* @brief Rename a tree item on demand of the context menu
*/
/*****************************************************************************/
void
WinEDA_PrjFrame
::
OnRename
(
wxTreeEvent
&
event
)
/***************************************************/
/* rename a tree item on demand of the context menu */
/*****************************************************************************/
{
TreePrjItemData
*
tree_data
=
GetSelectedData
();
...
...
@@ -962,9 +1126,13 @@ void WinEDA_PrjFrame::OnRename( wxTreeEvent& event )
}
/**************************************************/
/**
* @brief TODO
*/
/*****************************************************************************/
void
WinEDA_PrjFrame
::
OnSelect
(
wxTreeEvent
&
Event
)
/**************************************************/
/**************************************************
***************************
/
{
wxString
FullFileName
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment