3 * Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 * See the file ./license.txt
25 \date September 2006 - January 2007
26 \brief CANIMXY is a scope in 2D which draw its input as a XY scope, there is animation.
27 \see CANIMXY.sci in macros/scicos_blocks/Sinks/
29 #include "CurrentObjectsManagement.h"
30 #include "scoMemoryScope.h"
31 #include "scoWindowScope.h"
33 #include "scoGetProperty.h"
34 #include "scoSetProperty.h"
35 #include "scicos_block4.h"
36 #include "DrawingBridge.h"
38 /** \fn canimxy_draw(scicos_block * block, ScopeMemory ** pScopeMemory, int firstdraw)
39 \brief Function to draw or redraw the window
41 void canimxy_draw(scicos_block * block, ScopeMemory ** pScopeMemory, int firstdraw)
45 int gomme_color; //As usual
46 int * ipar; //Integer Parameters
47 int color_flag; //Flag on Color
51 int win; //Windows ID : To give a name to the window
52 int buffer_size; //Buffer Size
53 int win_pos[2]; //Position of the Window
54 int win_dim[2]; //Dimension of the Window
56 double * rpar; //Reals parameters
57 double xmin, xmax, ymin, ymax; //Ymin and Ymax are vectors here
58 scoGraphicalObject Pinceau; //Pointer to each polyline of each axes
59 scoGraphicalObject Gomme; //Pointer to each polyline of each axes
60 scoGraphicalObject Trait; //Pointer to each trache of each axes
62 int number_of_curves_by_subwin;
66 ipar = GetIparPtrs(block);
67 nipar = GetNipar(block);
68 rpar = GetRparPtrs(block);
71 buffer_size = ipar[2];
80 nbr_curves = ipar[10];
87 /* If only one element to draw*/
90 number_of_curves_by_subwin = nbr_curves;
93 scoInitScopeMemory(block->work,pScopeMemory, number_of_subwin, &number_of_curves_by_subwin);
94 scoSetShortDrawSize(*pScopeMemory,0,1);
95 scoSetLongDrawSize(*pScopeMemory,0,0);
97 scoInitOfWindow(*pScopeMemory, dimension, win, win_pos, win_dim, &xmin, &xmax, &ymin, &ymax, NULL, NULL);
98 if(scoGetScopeActivation(*pScopeMemory) == 1)
101 sciSetPixmapMode(scoGetPointerScopeWindow(*pScopeMemory),TRUE);
102 pFIGURE_FEATURE(scoGetPointerScopeWindow(*pScopeMemory))->pixmapMode = 1;
105 for(i = 0 ; i < scoGetNumberOfCurvesBySubwin(*pScopeMemory, 0) ; i++)
107 scoAddPolylineForShortDraw(*pScopeMemory,0,i,color[0]);
108 Pinceau = scoGetPointerShortDraw(*pScopeMemory,0,i);
109 pPOLYLINE_FEATURE(Pinceau)->n1 = 1;
110 sciSetMarkSize(Pinceau, line_size);
115 /*else if 2 or more elements*/
118 number_of_curves_by_subwin = 2*nbr_curves; //it is a trick to recognize the type of scope, not sure it is a good way because normally a curve is the combination of a short and a longdraw
121 scoInitScopeMemory(block->work,pScopeMemory, number_of_subwin, &number_of_curves_by_subwin);
124 scoInitOfWindow(*pScopeMemory, dimension, win, win_pos, win_dim, &xmin, &xmax, &ymin, &ymax, NULL, NULL);
125 if(scoGetScopeActivation(*pScopeMemory) == 1)
127 gomme_color = sciGetBackground(scoGetPointerAxes(*pScopeMemory,0));
128 //sciSetIsBoxed(scoGetPointerAxes(*pScopeMemory,0),FALSE); //** obsolete in Scilab 5
134 scoSetShortDrawSize(*pScopeMemory,0,1);
135 scoSetLongDrawSize(*pScopeMemory,0,buffer_size-1);
137 for(i = 0 ; i < nbr_curves ; i++)
139 //because of color[0] is negative it will add a black mark with style number color[0]
140 scoAddPolylineForShortDraw(*pScopeMemory,0,i,color[0]);
141 scoAddPolylineForShortDraw(*pScopeMemory,0,i+nbr_curves,color[0]); //same type of mark and black for the rubber
142 scoAddPolylineForLongDraw(*pScopeMemory,0,i,color[0]);
144 Pinceau = scoGetPointerShortDraw(*pScopeMemory,0,i);
145 Gomme = scoGetPointerShortDraw(*pScopeMemory,0,i+nbr_curves);
146 Trait = scoGetPointerLongDraw(*pScopeMemory,0,i);
148 pPOLYLINE_FEATURE(Pinceau)->n1 = 1;
149 pPOLYLINE_FEATURE(Gomme)->n1 = 1;
150 sciSetMarkForeground(Gomme, gomme_color); //here the rubber becomes colored like the background of the axes
151 pPOLYLINE_FEATURE(Trait)->n1 = buffer_size-1;
153 sciSetMarkSize(Pinceau, line_size);
154 sciSetMarkSize(Gomme, line_size);
155 sciSetMarkSize(Trait, line_size);
163 scoSetShortDrawSize(*pScopeMemory,0,2);
164 scoSetLongDrawSize(*pScopeMemory,0,buffer_size-1);
166 for(i = 0 ; i < nbr_curves ; i++)
168 scoAddPolylineForShortDraw(*pScopeMemory,0,i,color[0]);
169 scoAddPolylineForShortDraw(*pScopeMemory,0,i+nbr_curves,gomme_color);
170 scoAddPolylineForLongDraw(*pScopeMemory,0,i,color[0]);
172 Pinceau = scoGetPointerShortDraw(*pScopeMemory,0,i);
173 Gomme = scoGetPointerShortDraw(*pScopeMemory,0,i+nbr_curves);
174 Trait = scoGetPointerLongDraw(*pScopeMemory,0,i);
176 pPOLYLINE_FEATURE(Pinceau)->n1 = 2;
177 pPOLYLINE_FEATURE(Gomme)->n1 = 2;
178 pPOLYLINE_FEATURE(Trait)->n1 = buffer_size-1;
180 sciSetLineWidth(Pinceau, line_size);
181 sciSetLineWidth(Gomme, line_size);
182 sciSetLineWidth(Trait, line_size);
187 if(scoGetScopeActivation(*pScopeMemory) == 1)
189 scoAddTitlesScope(*pScopeMemory,"x","y",NULL);
193 /** \fn void canimxy(scicos_block * block, int flag)
194 \brief the computational function
195 \param block A pointer to a scicos_block
196 \param flag An int which indicates the state of the block (init, update, ending)
198 void canimxy(scicos_block * block, int flag)
201 ScopeMemory * pScopeMemory;
203 scoGraphicalObject pShortDraw,pLongDraw;
205 /* State Machine Control */
210 canimxy_draw(block,&pScopeMemory,1);
211 break; //Break of the switch condition don t forget it
212 } //End of Initialization
216 scoRetrieveScopeMemory(block->work,&pScopeMemory);
217 if(scoGetScopeActivation(pScopeMemory) == 1)
220 /* Charging Elements */
221 if (scoGetPointerScopeWindow(pScopeMemory) == NULL) // If the window has been destroyed we recreate it
223 canimxy_draw(block,&pScopeMemory,0);
226 /*Retrieve Elements*/
227 u1 = GetRealInPortPtrs(block,1);
228 u2 = GetRealInPortPtrs(block,2);
230 scoDrawScopeAnimXYStyle(pScopeMemory,u1,u2,NULL);
232 break; //Break of the switch don t forget it !
233 }//End of stateupdate
235 //This case is activated when the simulation is done or when we close scicos
238 scoRetrieveScopeMemory(block->work, &pScopeMemory);
239 if(scoGetScopeActivation(pScopeMemory) == 1)
241 /* sciSetUsedWindow(scoGetWindowID(pScopeMemory)); */
242 /* Check if figure is still opened, otherwise, don't try to destroy it again. */
243 scoGraphicalObject figure = scoGetPointerScopeWindow(pScopeMemory);
246 if(scoGetLongDrawSize(pScopeMemory,0) == 0)
248 for(i = 0 ; i < scoGetNumberOfCurvesBySubwin(pScopeMemory,0) ; i++)
250 pLongDraw = scoGetPointerLongDraw(pScopeMemory,0,i);
251 forceRedraw(pLongDraw);
256 for(i = 0 ; i < scoGetNumberOfCurvesBySubwin(pScopeMemory,0)/2 ; i++)
258 pLongDraw = scoGetPointerLongDraw(pScopeMemory,0,i);
259 forceRedraw(pLongDraw);
263 //Attention : here pShortDraw is a Window
264 /* pShortDraw = sciGetCurrentFigure(); */
265 /*pFIGURE_FEATURE(pShortDraw)->user_data = NULL;*/
266 /*pFIGURE_FEATURE(pShortDraw)->size_of_user_data = 0;*/
267 clearUserData(figure);
269 scoFreeScopeMemory(block->work, &pScopeMemory);
270 break; //Break of the switch
272 //free the memory which is allocated at each turn by some variables