You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

459 lines
15 KiB

  1. /****************************************************************/
  2. /* sheetlab.cpp module pour creation /editin des Sheet labels */
  3. /****************************************************************/
  4. #include "fctsys.h"
  5. #include "gr_basic.h"
  6. #include "common.h"
  7. #include "program.h"
  8. #include "libcmp.h"
  9. #include "general.h"
  10. #include "protos.h"
  11. /* Routines Locales */
  12. static void ExitPinSheet( WinEDA_DrawPanel* Panel, wxDC* DC );
  13. static void Move_PinSheet( WinEDA_DrawPanel* panel, wxDC* DC, bool erase );
  14. /* Variables locales */
  15. static int CurrentTypeLabel = NET_INPUT;
  16. static wxSize NetSheetTextSize( DEFAULT_SIZE_TEXT, DEFAULT_SIZE_TEXT );
  17. /****************************************/
  18. /* class WinEDA_PinSheetPropertiesFrame */
  19. /****************************************/
  20. #define NBSHAPES 5
  21. static wxString shape_list[NBSHAPES] =
  22. {
  23. wxT( "Input" ), wxT( "Output" ), wxT( "Bidi" ), wxT( "TriState" ), wxT( "Passive" )
  24. };
  25. /*****************************************************/
  26. class WinEDA_PinSheetPropertiesFrame : public wxDialog
  27. /*****************************************************/
  28. {
  29. private:
  30. WinEDA_SchematicFrame* m_Parent;
  31. DrawSheetLabelStruct* m_CurrentPinSheet;
  32. wxRadioBox* m_PinSheetType;
  33. wxRadioBox* m_PinSheetShape;
  34. WinEDA_GraphicTextCtrl* m_TextWin;
  35. public:
  36. // Constructor and destructor
  37. WinEDA_PinSheetPropertiesFrame( WinEDA_SchematicFrame* parent,
  38. DrawSheetLabelStruct* curr_pinsheet,
  39. const wxPoint& framepos = wxPoint( -1, -1 ) );
  40. ~WinEDA_PinSheetPropertiesFrame() { };
  41. private:
  42. void OnOkClick( wxCommandEvent& event );
  43. void OnCancelClick( wxCommandEvent& event );
  44. DECLARE_EVENT_TABLE()
  45. };
  46. BEGIN_EVENT_TABLE( WinEDA_PinSheetPropertiesFrame, wxDialog )
  47. EVT_BUTTON( wxID_OK, WinEDA_PinSheetPropertiesFrame::OnOkClick )
  48. EVT_BUTTON( wxID_CANCEL, WinEDA_PinSheetPropertiesFrame::OnCancelClick )
  49. END_EVENT_TABLE()
  50. /**********************************************************************************/
  51. WinEDA_PinSheetPropertiesFrame::WinEDA_PinSheetPropertiesFrame(
  52. WinEDA_SchematicFrame* parent,
  53. DrawSheetLabelStruct* curr_pinsheet,
  54. const wxPoint& framepos ) :
  55. wxDialog( parent, -1, _( "PinSheet Properties:" ), framepos, wxSize( 340, 220 ),
  56. DIALOG_STYLE )
  57. /**********************************************************************************/
  58. {
  59. wxPoint pos;
  60. wxString number;
  61. wxButton* Button;
  62. m_Parent = parent;
  63. Centre();
  64. wxBoxSizer* MainBoxSizer = new wxBoxSizer( wxHORIZONTAL );
  65. SetSizer( MainBoxSizer );
  66. wxBoxSizer* LeftBoxSizer = new wxBoxSizer( wxVERTICAL );
  67. wxBoxSizer* RightBoxSizer = new wxBoxSizer( wxVERTICAL );
  68. MainBoxSizer->Add( LeftBoxSizer, 0, wxGROW | wxALL, 5 );
  69. MainBoxSizer->Add( RightBoxSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
  70. m_CurrentPinSheet = curr_pinsheet;
  71. /* Creation des boutons de commande */
  72. Button = new wxButton( this, wxID_OK, _( "OK" ) );
  73. Button->SetForegroundColour( *wxRED );
  74. RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
  75. Button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) );
  76. Button->SetForegroundColour( *wxBLUE );
  77. RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
  78. m_TextWin = new WinEDA_GraphicTextCtrl( this, _( "Text:" ),
  79. m_CurrentPinSheet->m_Text, m_CurrentPinSheet->m_Size.x,
  80. g_UnitMetric, LeftBoxSizer, 200 );
  81. // Selection de la forme :
  82. m_PinSheetShape = new wxRadioBox( this, -1, _( "PinSheet Shape:" ),
  83. wxDefaultPosition, wxSize( -1, -1 ),
  84. NBSHAPES, shape_list, 1 );
  85. m_PinSheetShape->SetSelection( m_CurrentPinSheet->m_Shape );
  86. LeftBoxSizer->Add( m_PinSheetShape, 0, wxGROW | wxALL, 5 );
  87. GetSizer()->Fit( this );
  88. GetSizer()->SetSizeHints( this );
  89. }
  90. /************************************************************************/
  91. void WinEDA_PinSheetPropertiesFrame::OnCancelClick( wxCommandEvent& WXUNUSED (event) )
  92. /************************************************************************/
  93. {
  94. EndModal( -1 );
  95. }
  96. /***********************************************************************************/
  97. void WinEDA_PinSheetPropertiesFrame::OnOkClick( wxCommandEvent& event )
  98. /***********************************************************************************/
  99. {
  100. m_CurrentPinSheet->m_Text = m_TextWin->GetText();
  101. m_CurrentPinSheet->m_Size.x = m_CurrentPinSheet->m_Size.y = m_TextWin->GetTextSize();
  102. m_CurrentPinSheet->m_Shape = m_PinSheetShape->GetSelection();
  103. EndModal( 0 );
  104. }
  105. /*****************************************************************/
  106. static void ExitPinSheet( WinEDA_DrawPanel* Panel, wxDC* DC )
  107. /*****************************************************************/
  108. /* Routine de sortie du Menu d'Edition Des NETS (Labels) SHEET
  109. */
  110. {
  111. DrawSheetLabelStruct* SheetLabel = (DrawSheetLabelStruct*)
  112. Panel->GetScreen()->GetCurItem();
  113. if( SheetLabel == NULL )
  114. return;
  115. if( SheetLabel->m_Flags & IS_NEW )
  116. { /* Nouveau Placement en cours, on l'efface */
  117. RedrawOneStruct( Panel, DC, SheetLabel, g_XorMode );
  118. delete SheetLabel;
  119. }
  120. else
  121. {
  122. RedrawOneStruct( Panel, DC, SheetLabel, GR_DEFAULT_DRAWMODE );
  123. SheetLabel->m_Flags = 0;
  124. }
  125. Panel->GetScreen()->SetCurItem( NULL );
  126. Panel->ManageCurseur = NULL;
  127. Panel->ForceCloseManageCurseur = NULL;
  128. }
  129. /* Cette routine place un nouveau NetSheet ou place un ancien en cours
  130. * de deplacement
  131. * Si le NetSheet est nouveau, il est pointe par NewSheetLabel
  132. */
  133. void DrawSheetLabelStruct::Place( WinEDA_DrawFrame* frame, wxDC* DC )
  134. {
  135. DrawSheetStruct* Sheet = (DrawSheetStruct*) m_Parent;
  136. if( m_Flags & IS_NEW ) /* ajout a la liste des structures */
  137. {
  138. if( Sheet->m_Label == NULL )
  139. Sheet->m_Label = this;
  140. else
  141. {
  142. DrawSheetLabelStruct* pinsheet = Sheet->m_Label;
  143. while( pinsheet )
  144. {
  145. if( pinsheet->Pnext == NULL )
  146. {
  147. pinsheet->Pnext = this;
  148. break;
  149. }
  150. pinsheet = (DrawSheetLabelStruct*) pinsheet->Pnext;
  151. }
  152. }
  153. }
  154. m_Flags = 0;
  155. m_Pos.x = Sheet->m_Pos.x;
  156. m_Edge = 0;
  157. if( frame->GetScreen()->m_Curseur.x > ( Sheet->m_Pos.x + (Sheet->m_Size.x / 2) ) )
  158. {
  159. m_Edge = 1;
  160. m_Pos.x = Sheet->m_Pos.x + Sheet->m_Size.x;
  161. }
  162. m_Pos.y = frame->GetScreen()->m_Curseur.y;
  163. if( m_Pos.y < Sheet->m_Pos.y )
  164. m_Pos.y = Sheet->m_Pos.y;
  165. if( m_Pos.y > (Sheet->m_Pos.y + Sheet->m_Size.y) )
  166. m_Pos.y = Sheet->m_Pos.y + Sheet->m_Size.y;
  167. RedrawOneStruct( frame->DrawPanel, DC, Sheet, GR_DEFAULT_DRAWMODE );
  168. frame->DrawPanel->ManageCurseur = NULL;
  169. frame->DrawPanel->ForceCloseManageCurseur = NULL;
  170. }
  171. /*******************************************************************************/
  172. void WinEDA_SchematicFrame::StartMove_PinSheet( DrawSheetLabelStruct* SheetLabel,
  173. wxDC* DC )
  174. /*******************************************************************************/
  175. /* Initialise un deplacement de NetSheet */
  176. {
  177. NetSheetTextSize = SheetLabel->m_Size;
  178. CurrentTypeLabel = SheetLabel->m_Shape;
  179. SheetLabel->m_Flags |= IS_MOVED;
  180. DrawPanel->ManageCurseur = Move_PinSheet;
  181. DrawPanel->ForceCloseManageCurseur = ExitPinSheet;
  182. DrawPanel->ManageCurseur( DrawPanel, DC, TRUE );
  183. }
  184. /**********************************************************************/
  185. /* Routine de deplacement du NetSheet actif selon la position souris */
  186. /**********************************************************************/
  187. static void Move_PinSheet( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
  188. {
  189. DrawSheetLabelStruct* SheetLabel = (DrawSheetLabelStruct*)
  190. panel->m_Parent->GetScreen()->GetCurItem();
  191. if( SheetLabel == NULL )
  192. return;
  193. DrawSheetStruct* Sheet = (DrawSheetStruct*) SheetLabel->m_Parent;
  194. if( Sheet == NULL )
  195. return;
  196. if( erase )
  197. RedrawOneStruct( panel, DC, SheetLabel, g_XorMode );
  198. SheetLabel->m_Edge = 0;
  199. SheetLabel->m_Pos.x = Sheet->m_Pos.x;
  200. if( panel->m_Parent->GetScreen()->m_Curseur.x > ( Sheet->m_Pos.x + (Sheet->m_Size.x / 2) ) )
  201. {
  202. SheetLabel->m_Edge = 1;
  203. SheetLabel->m_Pos.x = Sheet->m_Pos.x + Sheet->m_Size.x;
  204. }
  205. SheetLabel->m_Pos.y = panel->m_Parent->GetScreen()->m_Curseur.y;
  206. if( SheetLabel->m_Pos.y < Sheet->m_Pos.y )
  207. SheetLabel->m_Pos.y = Sheet->m_Pos.y;
  208. if( SheetLabel->m_Pos.y > (Sheet->m_Pos.y + Sheet->m_Size.y) )
  209. SheetLabel->m_Pos.y = Sheet->m_Pos.y + Sheet->m_Size.y;
  210. RedrawOneStruct( panel, DC, SheetLabel, g_XorMode );
  211. }
  212. /***************************************************************************/
  213. void WinEDA_SchematicFrame::Edit_PinSheet( DrawSheetLabelStruct* SheetLabel,
  214. wxDC* DC )
  215. /***************************************************************************/
  216. /* Modification du texte d'un net sheet */
  217. {
  218. if( SheetLabel == NULL )
  219. return;
  220. RedrawOneStruct( DrawPanel, DC, SheetLabel, g_XorMode );
  221. WinEDA_PinSheetPropertiesFrame* frame =
  222. new WinEDA_PinSheetPropertiesFrame( this, SheetLabel );
  223. frame->ShowModal(); frame->Destroy();
  224. RedrawOneStruct( DrawPanel, DC, SheetLabel, GR_DEFAULT_DRAWMODE );
  225. }
  226. /***************************************************************/
  227. DrawSheetLabelStruct* WinEDA_SchematicFrame::Create_PinSheet(
  228. DrawSheetStruct* Sheet, wxDC* DC )
  229. /**************************************************************/
  230. /* Addition d'un nouveau PinSheet sur la feuille selectionnee, a l'endroit
  231. * pointe par la souris
  232. */
  233. {
  234. wxString Line, Text;
  235. DrawSheetLabelStruct* NewSheetLabel;
  236. switch( CurrentTypeLabel )
  237. {
  238. default:
  239. CurrentTypeLabel = NET_INPUT;
  240. case NET_INPUT:
  241. Text = wxT( "Pin Input: " );
  242. break;
  243. case NET_OUTPUT:
  244. Text = wxT( "Pin Output: " );
  245. break;
  246. case NET_BIDI:
  247. Text = wxT( "Pin BiDi: " );
  248. break;
  249. case NET_TRISTATE:
  250. Text = wxT( "Pin TriStat: " );
  251. break;
  252. case NET_UNSPECIFIED:
  253. Text = wxT( "Pin Unspec.: " );
  254. break;
  255. }
  256. Get_Message( Text, Line, this );
  257. if( Line.IsEmpty() )
  258. return NULL;
  259. GetScreen()->SetModify();
  260. /* Creation en memoire */
  261. NewSheetLabel = new DrawSheetLabelStruct( Sheet, wxPoint( 0, 0 ), Line );
  262. NewSheetLabel->m_Flags = IS_NEW;
  263. NewSheetLabel->m_Size = NetSheetTextSize;
  264. NewSheetLabel->m_Shape = CurrentTypeLabel;
  265. GetScreen()->SetCurItem( NewSheetLabel );
  266. DrawPanel->ManageCurseur = Move_PinSheet;
  267. DrawPanel->ForceCloseManageCurseur = ExitPinSheet;
  268. DrawPanel->ManageCurseur( DrawPanel, DC, TRUE );
  269. return NewSheetLabel;
  270. }
  271. /*****************************************************************************/
  272. DrawSheetLabelStruct* WinEDA_SchematicFrame::Import_PinSheet( DrawSheetStruct* Sheet, wxDC* DC )
  273. /*****************************************************************************/
  274. /* Permet de creer automatiquement les Sheet Labels a partir des Labels Globaux
  275. * de la feuille de sous hierarchie correspondante
  276. */
  277. {
  278. EDA_BaseStruct* DrawStruct;
  279. DrawSheetLabelStruct* NewSheetLabel, * SheetLabel = NULL;
  280. DrawGlobalLabelStruct* GLabel = NULL;
  281. DrawStruct = Sheet->EEDrawList;
  282. GLabel = NULL;
  283. for( ; DrawStruct != NULL; DrawStruct = DrawStruct->Pnext )
  284. {
  285. if( DrawStruct->Type() != DRAW_GLOBAL_LABEL_STRUCT_TYPE )
  286. continue;
  287. GLabel = (DrawGlobalLabelStruct*) DrawStruct;
  288. /* Ici un G-Label a ete trouve: y a t-il un SheetLabel correspondant */
  289. SheetLabel = Sheet->m_Label;
  290. for( ; SheetLabel != NULL; SheetLabel = (DrawSheetLabelStruct*) SheetLabel->Pnext )
  291. {
  292. if( SheetLabel->m_Text.CmpNoCase( GLabel->m_Text ) == 0 )
  293. {
  294. break;
  295. }
  296. }
  297. /* Ici si SheetLabel == NULL le G-Label n'a pas de SheetLabel corresp */
  298. if( SheetLabel == NULL )
  299. break;
  300. }
  301. if( (GLabel == NULL ) || SheetLabel )
  302. {
  303. DisplayError( this, _( "No New Global Label found" ), 10 );
  304. return NULL;
  305. }
  306. /* Ici G-Label n'a pas de SheetLabel corresp, on va le creer */
  307. GetScreen()->SetModify();
  308. /* Creation en memoire */
  309. NewSheetLabel = new DrawSheetLabelStruct( Sheet, wxPoint( 0, 0 ), GLabel->m_Text );
  310. NewSheetLabel->m_Flags = IS_NEW;
  311. NewSheetLabel->m_Size = NetSheetTextSize;
  312. CurrentTypeLabel = NewSheetLabel->m_Shape = GLabel->m_Shape;
  313. GetScreen()->SetCurItem( NewSheetLabel );
  314. DrawPanel->ManageCurseur = Move_PinSheet;
  315. DrawPanel->ForceCloseManageCurseur = ExitPinSheet;
  316. Move_PinSheet( DrawPanel, DC, FALSE );
  317. return NewSheetLabel;
  318. }
  319. /**************************************************************/
  320. void WinEDA_SchematicFrame::DeleteSheetLabel( wxDC* DC,
  321. DrawSheetLabelStruct* SheetLabelToDel )
  322. /**************************************************************/
  323. /*
  324. * Routine de suppression de 1 Structure type (DrawSheetLabelStruct.
  325. * Cette Structure ne peut etre mise en pile "undelete" car il ne serait pas
  326. * possible de la ratacher a la 'DrawSheetStruct' d'origine
  327. * si DC != NULL, effacement a l'ecran du dessin
  328. */
  329. {
  330. EDA_BaseStruct* DrawStruct;
  331. DrawSheetLabelStruct* SheetLabel, * NextLabel;
  332. if( DC )
  333. RedrawOneStruct( DrawPanel, DC, SheetLabelToDel, g_XorMode );
  334. /* Recherche de la DrawSheetStruct d'origine */
  335. DrawStruct = SheetLabelToDel->m_Parent;
  336. if( DrawStruct ) // Modification du chainage
  337. {
  338. if( DrawStruct->Type() != DRAW_SHEET_STRUCT_TYPE )
  339. {
  340. DisplayError( this,
  341. wxT( "DeleteSheetLabel error: m_Parent != DRAW_SHEET_STRUCT_TYPE" ) );
  342. return;
  343. }
  344. /* suppression chainage */
  345. SheetLabel = ( (DrawSheetStruct*) DrawStruct )->m_Label;
  346. if( SheetLabel == SheetLabelToDel )
  347. ( (DrawSheetStruct*) DrawStruct )->m_Label =
  348. (DrawSheetLabelStruct*) SheetLabel->Pnext;
  349. else
  350. while( SheetLabel ) /* Examen de la liste dependante et suppression chainage */
  351. {
  352. NextLabel = (DrawSheetLabelStruct*) SheetLabel->Pnext;
  353. if( NextLabel == SheetLabelToDel )
  354. {
  355. SheetLabel->Pnext = NextLabel->Pnext;
  356. break;;
  357. }
  358. SheetLabel = NextLabel;
  359. }
  360. }
  361. delete SheetLabelToDel;
  362. }