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.

317 lines
14 KiB

  1. /****************************************************/
  2. /* drawpanel_wxstruct.h: */
  3. /* descriptions des principales classes utilisees: */
  4. /* ici classe: "WinEDA_DrawPanel", "BASE_SCREEN" */
  5. /*****************************************************/
  6. /* Doit etre inclus dans "wxstruch.h"
  7. */
  8. #ifndef PANEL_WXSTRUCT_H
  9. #define PANEL_WXSTRUCT_H
  10. #ifndef eda_global
  11. #define eda_global extern
  12. #endif
  13. #include "colors.h"
  14. /****************************************************/
  15. /* classe representant un ecran graphique de dessin */
  16. /****************************************************/
  17. class WinEDA_DrawPanel : public EDA_DRAW_PANEL
  18. {
  19. public:
  20. int m_Ident;
  21. WinEDA_DrawFrame* m_Parent;
  22. EDA_Rect m_ClipBox; /* position et taille de la fenetre de trace
  23. * pour les "RePaint" d'ecran */
  24. wxPoint m_CursorStartPos; // utile dans controles du mouvement curseur
  25. int m_Scroll_unit; // Valeur de l'unite de scroll en pixels pour les barres de scroll
  26. int m_ScrollButt_unit; // Valeur de l'unite de scroll en pixels pour les boutons de scroll
  27. bool m_AbortRequest; // Flag d'arret de commandes longues
  28. bool m_AbortEnable; // TRUE si menu ou bouton Abort doit etre affiche
  29. bool m_AutoPAN_Enable; // TRUE pour autoriser auto pan (autorisation g��ale)
  30. bool m_AutoPAN_Request; // TRUE pour auto pan (lorsque auto pan n�essaire)
  31. bool m_IgnoreMouseEvents; // TRUE pour ne par traiter les evenements souris
  32. bool m_Block_Enable; // TRUE pour autoriser Bloc Commandes (autorisation g��ale)
  33. int m_CanStartBlock; // >= 0 (ou >= n) si un bloc peut demarrer
  34. // (filtrage des commandes de debut de bloc )
  35. int m_PanelDefaultCursor; // Current mouse cursor default shape id for this window
  36. int m_PanelCursor; // Current mouse cursor shape id for this window
  37. int m_CursorLevel; // Index for cursor redraw in XOR mode
  38. /* Cursor management (used in editing functions) */
  39. void (*ManageCurseur)(WinEDA_DrawPanel * panel, wxDC * DC, bool erase);/* Fonction d'affichage sur deplacement souris
  40. * si erase : effacement ancien affichage */
  41. void (*ForceCloseManageCurseur)(WinEDA_DrawPanel * panel, wxDC * DC);/* Fonction de fermeture forc�
  42. * de la fonction ManageCurseur */
  43. public:
  44. // Constructor and destructor
  45. WinEDA_DrawPanel( WinEDA_DrawFrame* parent, int id, const wxPoint& pos, const wxSize& size );
  46. ~WinEDA_DrawPanel( void ) { }
  47. /****************************/
  48. BASE_SCREEN* GetScreen( void ) { return m_Parent->m_CurrentScreen; }
  49. void PrepareGraphicContext( wxDC* DC );
  50. wxPoint CalcAbsolutePosition( const wxPoint& rel_pos );
  51. bool IsPointOnDisplay( wxPoint ref_pos );
  52. void OnPaint( wxPaintEvent& event );
  53. void OnSize( wxSizeEvent& event );
  54. void SetBoundaryBox( void );
  55. void ReDraw( wxDC* DC, bool erasebg = TRUE );
  56. void PrintPage( wxDC* DC, bool Print_Sheet_Ref, int PrintMask );
  57. void DrawBackGround( wxDC* DC );
  58. void m_Draw_Auxiliary_Axis( wxDC* DC, int drawmode );
  59. void OnEraseBackground( wxEraseEvent& event );
  60. void OnActivate( wxActivateEvent& event );
  61. /* Mouse and keys events */
  62. void OnMouseEvent( wxMouseEvent& event );
  63. void OnMouseLeaving( wxMouseEvent& event );
  64. void OnKeyEvent( wxKeyEvent& event );
  65. /*************************/
  66. void EraseScreen( wxDC* DC );
  67. void OnScrollWin( wxCommandEvent& event );
  68. void OnScroll( wxScrollWinEvent& event );
  69. void SetZoom( int mode );
  70. int GetZoom( void );
  71. void SetGrid( const wxSize& size );
  72. wxSize GetGrid( void );
  73. void AddMenuZoom( wxMenu* MasterMenu );
  74. void OnRightClick( wxMouseEvent& event );
  75. void Process_Popup_Zoom( wxCommandEvent& event );
  76. void Process_Special_Functions( wxCommandEvent& event );
  77. wxPoint CursorRealPosition( const wxPoint& ScreenPos );
  78. wxPoint CursorScreenPosition( void );
  79. wxPoint GetScreenCenterRealPosition( void );
  80. void MouseToCursorSchema( void );
  81. void MouseTo( const wxPoint& Mouse );
  82. /* Cursor functions */
  83. void Trace_Curseur( wxDC* DC, int color = WHITE ); // Draw the user cursor (grid cursor)
  84. void CursorOff( wxDC* DC ); // remove the grid cursor from the display
  85. void CursorOn( wxDC* DC ); // display the grid cursor
  86. DECLARE_EVENT_TABLE()
  87. };
  88. /**************************/
  89. /* class DrawBlockStruct */
  90. /**************************/
  91. /* Definition d'un block pour les fonctions sur block (block move, ..) */
  92. typedef enum { /* definition de l'etat du block */
  93. STATE_NO_BLOCK, /* Block non initialise */
  94. STATE_BLOCK_INIT, /* Block initialise: 1er point defini */
  95. STATE_BLOCK_END, /* Block initialise: 2eme point defini */
  96. STATE_BLOCK_MOVE, /* Block en deplacement */
  97. STATE_BLOCK_STOP /* Block fixe (fin de deplacement) */
  98. } BlockState;
  99. /* codes des differentes commandes sur block: */
  100. typedef enum {
  101. BLOCK_IDLE,
  102. BLOCK_MOVE,
  103. BLOCK_COPY,
  104. BLOCK_SAVE,
  105. BLOCK_DELETE,
  106. BLOCK_PASTE,
  107. BLOCK_DRAG,
  108. BLOCK_ROTATE,
  109. BLOCK_INVERT,
  110. BLOCK_ZOOM,
  111. BLOCK_ABORT,
  112. BLOCK_PRESELECT_MOVE,
  113. BLOCK_SELECT_ITEMS_ONLY,
  114. BLOCK_MIRROR_X,
  115. BLOCK_MIRROR_Y
  116. } CmdBlockType;
  117. class DrawBlockStruct : public EDA_BaseStruct, public EDA_Rect
  118. {
  119. public:
  120. BlockState m_State; /* Etat (enum BlockState) du block */
  121. CmdBlockType m_Command; /* Type (enum CmdBlockType) d'operation */
  122. EDA_BaseStruct* m_BlockDrawStruct; /* pointeur sur la structure
  123. * selectionnee dans le bloc */
  124. int m_Color; /* Block Color */
  125. wxPoint m_MoveVector; /* Move distance in move, drag, copy ... command */
  126. wxPoint m_BlockLastCursorPosition;/* Last Mouse position in block command
  127. * = last cursor position in move commands
  128. * = 0,0 in block paste */
  129. public:
  130. DrawBlockStruct( void );
  131. ~DrawBlockStruct( void );
  132. void SetMessageBlock( WinEDA_DrawFrame* frame );
  133. void Draw( WinEDA_DrawPanel* panel, wxDC* DC );
  134. };
  135. /*******************************************************************/
  136. /* Class to handle how to draw a screen (a board, a schematic ...) */
  137. /*******************************************************************/
  138. class BASE_SCREEN : public EDA_BaseStruct
  139. {
  140. public:
  141. int m_Type; /* indicateur: type d'ecran */
  142. wxPoint m_DrawOrg; /* offsets pour tracer le circuit sur l'ecran */
  143. wxPoint m_Curseur; /* Screen cursor coordinate (on grid) in user units. */
  144. wxPoint m_MousePosition; /* Mouse cursor coordinate (off grid) in user units. */
  145. wxPoint m_MousePositionInPixels; /* Mouse cursor coordinate (off grid) in pixels. */
  146. wxPoint m_O_Curseur; /* Relative Screen cursor coordinate (on grid) in user units.
  147. * (coordinates from last reset position)*/
  148. wxPoint m_ScrollbarPos; // Position effective des Curseurs de scroll
  149. wxSize m_ScrollbarNumber; /* Valeur effective des Nombres de Scrool
  150. * c.a.d taille en unites de scroll de la surface totale affichable */
  151. wxPoint m_StartVisu; // Coord absolues du 1er pixel visualis�a l'ecran (en nombre de pixels)
  152. wxSize m_SizeVisu; /* taille en pixels de l'ecran (fenetre de visu
  153. * Utile pour recadrer les affichages lors de la
  154. * navigation dans la hierarchie */
  155. bool m_Center; // TRUE: coord algebriques, FALSE: coord >= 0
  156. bool m_FirstRedraw;
  157. /* Gestion des editions */
  158. EDA_BaseStruct* EEDrawList; /* Object list (main data) for schematic */
  159. EDA_BaseStruct* m_UndoList; /* Object list for the undo command (old data) */
  160. EDA_BaseStruct* m_RedoList; /* Object list for the redo command (old data) */
  161. int m_UndoRedoCountMax; /* undo/Redo command Max depth */
  162. /* block control */
  163. DrawBlockStruct BlockLocate; /* Bock description for block commands */
  164. /* Page description */
  165. Ki_PageDescr* m_CurrentSheet;
  166. int m_SheetNumber, m_NumberOfSheet;/* gestion hierarchie: numero de sousfeuille
  167. * et nombre de feuilles. Root: SheetNumber = 1 */
  168. wxString m_FileName;
  169. wxString m_Title; /* titre de la feuille */
  170. wxString m_Date; /* date de mise a jour */
  171. wxString m_Revision; /* code de revision */
  172. wxString m_Company; /* nom du proprietaire */
  173. wxString m_Commentaire1;
  174. wxString m_Commentaire2;
  175. wxString m_Commentaire3;
  176. wxString m_Commentaire4;
  177. private:
  178. /* indicateurs divers */
  179. char m_FlagRefreshReq; /* indique que l'ecran doit redessine */
  180. char m_FlagModified; // indique modif du PCB,utilise pour eviter une sortie sans sauvegarde
  181. char m_FlagSave; // indique sauvegarde auto faite
  182. EDA_BaseStruct* m_CurrentItem; /* Current selected object */
  183. /* Valeurs du pas de grille et du zoom */
  184. public:
  185. wxSize m_Grid; /* pas de la grille (peut differer en X et Y) */
  186. wxSize* m_GridList; /* Liste des valeurs standard de grille */
  187. wxRealPoint m_UserGrid; /* pas de la grille utilisateur */
  188. int m_UserGridUnit; /* unit�grille utilisateur (0 = inch, 1 = mm */
  189. int m_Diviseur_Grille;
  190. bool m_UserGridIsON;
  191. int* m_ZoomList; /* Liste des coefficients standard de zoom */
  192. int m_Zoom; /* coeff de ZOOM */
  193. public:
  194. BASE_SCREEN( int idscreen );
  195. ~BASE_SCREEN( void );
  196. void InitDatas( void );/* Inits completes des variables */
  197. wxSize ReturnPageSize( void );
  198. int GetInternalUnits( void );
  199. wxPoint CursorRealPosition( const wxPoint& ScreenPos );
  200. /* general Undo/Redo command control */
  201. virtual void ClearUndoRedoList( void );
  202. virtual void AddItemToUndoList( EDA_BaseStruct* item );
  203. virtual void AddItemToRedoList( EDA_BaseStruct* item );
  204. virtual EDA_BaseStruct* GetItemFromUndoList( void );
  205. virtual EDA_BaseStruct* GetItemFromRedoList( void );
  206. /* Manipulation des flags */
  207. void SetRefreshReq( void ) { m_FlagRefreshReq = 1; }
  208. void ClrRefreshReq( void ) { m_FlagRefreshReq = 0; }
  209. void SetModify( void ) { m_FlagModified = 1; m_FlagSave = 0; }
  210. void ClrModify( void ) { m_FlagModified = 0; m_FlagSave = 1; }
  211. void SetSave( void ) { m_FlagSave = 1; }
  212. void ClrSave( void ) { m_FlagSave = 0; }
  213. int IsModify( void ) { return m_FlagModified & 1; }
  214. int IsRefreshReq( void ) { return m_FlagRefreshReq & 1; }
  215. int IsSave( void ) { return m_FlagSave & 1; }
  216. /**
  217. * Function SetCurItem
  218. * sets the currently selected object, m_CurrentItem.
  219. * This is intentionally not inlined so we can set breakpoints on the
  220. * activity easier in base_screen.cpp.
  221. * @param current Any object derived from EDA_BaseStruct
  222. */
  223. void SetCurItem( EDA_BaseStruct* current );
  224. EDA_BaseStruct* GetCurItem() const { return m_CurrentItem; }
  225. /* fonctions relatives au zoom */
  226. int GetZoom( void ); /* retourne le coeff de zoom */
  227. void SetZoom( int coeff ); /* ajuste le coeff de zoom a coeff */
  228. void SetZoomList( int* zoomlist ); /* init liste des zoom (NULL terminated) */
  229. void SetNextZoom( void ); /* ajuste le prochain coeff de zoom */
  230. void SetPreviousZoom( void ); /* ajuste le precedent coeff de zoom */
  231. void SetFirstZoom( void ); /* ajuste le coeff de zoom a 1*/
  232. void SetLastZoom( void ); /* ajuste le coeff de zoom au max */
  233. /* fonctions relatives a la grille */
  234. wxSize GetGrid( void ); /* retourne la grille */
  235. void SetGrid( const wxSize& size );
  236. void SetGridList( wxSize* sizelist ); /* init liste des grilles (NULL terminated) */
  237. void SetNextGrid( void ); /* ajuste le prochain coeff de grille */
  238. void SetPreviousGrid( void ); /* ajuste le precedent coeff de grille */
  239. void SetFirstGrid( void ); /* ajuste la grille au mini*/
  240. void SetLastGrid( void ); /* ajuste la grille au max */
  241. /**
  242. * Function RefPos
  243. * returns the reference position, coming from either the mouse position or the
  244. * the cursor position.
  245. * @param useMouse If true, return mouse posistion, else cursor's.
  246. * @return wxPoint - The reference point, either the mouse position or
  247. * the cursor position.
  248. */
  249. wxPoint RefPos( bool useMouse )
  250. {
  251. return useMouse ? m_MousePosition : m_Curseur;
  252. }
  253. #if defined (DEBUG)
  254. /**
  255. * Function GetClass
  256. * returns the class name.
  257. * @return wxString
  258. */
  259. virtual wxString GetClass() const
  260. {
  261. return wxT( "BASE_SCREEN" );
  262. }
  263. #endif
  264. };
  265. #endif /* PANEL_WXSTRUCT_H */