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 CEVSCPE is a scope that indicates when the clocks is activated
27 \see CEVENTSCOPE.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"
37 #include "SetJavaProperty.h"
39 /** \fn cscopxy_draw(scicos_block * block, ScopeMemory ** pScopeMemory, int firstdraw)
40 \brief Function to draw or redraw the window
42 void cevscpe_draw(scicos_block * block, ScopeMemory ** pScopeMemory, int firstdraw)
46 int nipar; //Number of elements in ipar vector
49 double * rpar; //Integer Parameter
50 int nbr_colors; //Number of colors and lines IS ALSO number of channels
51 int win; //To give a name to the window
52 int color_flag; //0/1 color flag -- NOT USED
53 int * colors; //Begin at ipar[2] and has a measure of 8 max
55 double period; //Refresh Period of the scope is a vector here
57 int number_of_curves_by_subwin;
58 double xmin, xmax, ymin, ymax;
59 int win_pos[2], win_dim[2];
62 ipar = GetIparPtrs(block);
64 color_flag = ipar[1]; /*not used*/
65 rpar = GetRparPtrs(block);
67 nipar = GetNipar(block);
69 colors=(int*)scicos_malloc(nbr_colors*sizeof(int));
70 for( i = 2 ; i < nbr_colors+2 ; i++)
72 colors[i-2] = ipar[i];
76 number_of_curves_by_subwin = nbr_colors;
81 win_pos[0] = ipar[(nipar-1) - 3];
82 win_pos[1] = ipar[(nipar-1) - 2];
83 win_dim[0] = ipar[(nipar-1) - 1];
84 win_dim[1] = ipar[nipar-1];
88 scoInitScopeMemory(block->work,pScopeMemory, number_of_subwin, &number_of_curves_by_subwin);
89 scoSetLongDrawSize(*pScopeMemory,0,5000);
90 scoSetShortDrawSize(*pScopeMemory,0,1);
91 scoSetPeriod(*pScopeMemory,0,period);
94 xmin = period*scoGetPeriodCounter(*pScopeMemory,0);
95 xmax = period*(scoGetPeriodCounter(*pScopeMemory,0)+1);
97 scoInitOfWindow(*pScopeMemory, dimension, win, win_pos, win_dim, &xmin, &xmax, &ymin, &ymax, NULL, NULL);
98 if(scoGetScopeActivation(*pScopeMemory) == 1)
100 scoAddTitlesScope(*pScopeMemory,"t","y",NULL);
101 scoAddCoupleOfSegments(*pScopeMemory,colors);
105 /* use only single buffering to be sure to draw on the screen */
106 sciSetJavaUseSingleBuffer(scoGetPointerScopeWindow(*pScopeMemory), TRUE);
109 /** \fn void cevscpe(scicos_block * block, int flag)
110 \brief the computational function
111 \param block A pointer to a scicos_block
112 \param flag An int which indicates the state of the block (init, update, ending)
114 void cevscpe(scicos_block * block, int flag)
117 ScopeMemory * pScopeMemory;
120 scoGraphicalObject pShortDraw, pLongDraw;
128 cevscpe_draw(block,&pScopeMemory,1);
135 /* Charging elements */
137 scoRetrieveScopeMemory(block->work,&pScopeMemory);
139 if(scoGetScopeActivation(pScopeMemory) == 1)
142 t = get_scicos_time();
143 if(scoGetPointerScopeWindow(pScopeMemory) == NULL)
145 cevscpe_draw(block,&pScopeMemory,0);
148 scoRefreshDataBoundsX(pScopeMemory,t);
152 for(i = 0 ; i < scoGetNumberOfCurvesBySubwin(pScopeMemory,0) ; i++)
154 if((GetNevIn(block)&(1<<i))==(1<<i))
161 for(i = 0 ; i < nbseg ; i++)
163 pShortDraw = scoGetPointerShortDraw(pScopeMemory,0,tab[i]);
164 pSEGS_FEATURE(pShortDraw)->vx[0] = t;
165 pSEGS_FEATURE(pShortDraw)->vx[1] = t;
166 pSEGS_FEATURE(pShortDraw)->vy[0] = i*0.8/nbseg;
167 pSEGS_FEATURE(pShortDraw)->vy[1] = (i+1)*0.8/nbseg;
168 pSEGS_FEATURE(pShortDraw)->Nbr1 = 2;
169 pSEGS_FEATURE(pShortDraw)->Nbr2 = 2;
171 /*End of Not Factorize*/
172 scoDrawScopeAmplitudeTimeStyle(pScopeMemory,t);
180 scoRetrieveScopeMemory(block->work, &pScopeMemory);
181 if(scoGetScopeActivation(pScopeMemory) == 1)
183 /* sciSetUsedWindow(scoGetWindowID(pScopeMemory)); */
184 /* Check if figure is still opened, otherwise, don't try to destroy it again. */
185 if(scoGetPointerScopeWindow(pScopeMemory) != NULL)
187 for(i = 0 ; i < scoGetNumberOfCurvesBySubwin(pScopeMemory,0) ; i++)
189 /* maybe a bug here in the last argument of the following instruction (see tab[i]) */
190 pLongDraw = scoGetPointerLongDraw(pScopeMemory,0,i);
191 forceRedraw(pLongDraw);
195 /* pShortDraw = sciGetCurrentFigure(); */
196 pShortDraw = scoGetPointerScopeWindow(pScopeMemory);
197 clearUserData(pShortDraw);
198 /* pFIGURE_FEATURE(pShortDraw)->user_data = NULL; */
199 /* pFIGURE_FEATURE(pShortDraw)->size_of_user_data = 0; */
200 /* restore double buffering */
201 sciSetJavaUseSingleBuffer(pShortDraw, FALSE);
202 scoDelCoupleOfSegments(pScopeMemory);
205 scoFreeScopeMemory(block->work,&pScopeMemory);