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
21 /*--------------------------------------------------------------------------*/
26 \date September 2006 - January 2007
27 \brief CEVSCPE is a scope that indicates when the clocks is activated
28 \see CEVENTSCOPE.sci in macros/scicos_blocks/Sinks/
30 /*--------------------------------------------------------------------------*/
31 #include "CurrentObjectsManagement.h"
33 #include "scoMemoryScope.h"
34 #include "scoWindowScope.h"
36 #include "scoGetProperty.h"
37 #include "scoSetProperty.h"
38 #include "scicos_block4.h"
39 #include "DrawingBridge.h"
40 #include "SetJavaProperty.h"
41 #include "scicos_malloc.h"
42 #include "scicos_free.h"
44 #include "dynlib_scicos_blocks.h"
45 /*--------------------------------------------------------------------------*/
46 /** \fn cscopxy_draw(scicos_block * block, ScopeMemory ** pScopeMemory, int firstdraw)
47 \brief Function to draw or redraw the window
49 SCICOS_BLOCKS_IMPEXP void cevscpe_draw(scicos_block * block, ScopeMemory ** pScopeMemory, int firstdraw)
53 int nipar = 0; //Number of elements in ipar vector
56 double * rpar = NULL; //Integer Parameter
57 int nbr_colors = 0; //Number of colors and lines IS ALSO number of channels
58 int win = 0; //To give a name to the window
59 int color_flag = 0; //0/1 color flag -- NOT USED
60 int * colors = NULL; //Begin at ipar[2] and has a measure of 8 max
62 double period = 0.; //Refresh Period of the scope is a vector here
63 int number_of_subwin = 0;
64 int number_of_curves_by_subwin = 0;
65 double xmin = 0., xmax = 0., ymin = 0., ymax = 0;
66 int win_pos[2], win_dim[2];
70 ipar = GetIparPtrs(block);
72 color_flag = ipar[1]; /*not used*/
73 rpar = GetRparPtrs(block);
75 nipar = GetNipar(block);
76 label = GetLabelPtrs(block);
78 colors=(int*)scicos_malloc(nbr_colors*sizeof(int));
79 for( i = 2 ; i < nbr_colors+2 ; i++)
81 colors[i-2] = ipar[i];
85 number_of_curves_by_subwin = nbr_colors;
90 win_pos[0] = ipar[(nipar-1) - 3];
91 win_pos[1] = ipar[(nipar-1) - 2];
92 win_dim[0] = ipar[(nipar-1) - 1];
93 win_dim[1] = ipar[nipar-1];
97 scoInitScopeMemory(block->work,pScopeMemory, number_of_subwin, &number_of_curves_by_subwin);
98 scoSetLongDrawSize(*pScopeMemory,0,5000);
99 scoSetShortDrawSize(*pScopeMemory,0,1);
100 scoSetPeriod(*pScopeMemory,0,period);
103 xmin = period*scoGetPeriodCounter(*pScopeMemory,0);
104 xmax = period*(scoGetPeriodCounter(*pScopeMemory,0)+1);
106 scoInitOfWindow(*pScopeMemory, dimension, win, win_pos, win_dim, &xmin, &xmax, &ymin, &ymax, NULL, NULL);
107 if(scoGetScopeActivation(*pScopeMemory) == 1)
109 scoAddTitlesScope(*pScopeMemory,label,"t","y",NULL);
110 scoAddCoupleOfSegments(*pScopeMemory,colors);
114 /* use only single buffering to be sure to draw on the screen */
115 if (scoGetPointerScopeWindow(*pScopeMemory) != NULL) {
116 sciSetJavaUseSingleBuffer(scoGetPointerScopeWindow(*pScopeMemory), TRUE);
119 /*--------------------------------------------------------------------------*/
120 /** \fn void cevscpe(scicos_block * block, int flag)
121 \brief the computational function
122 \param block A pointer to a scicos_block
123 \param flag An int which indicates the state of the block (init, update, ending)
125 SCICOS_BLOCKS_IMPEXP void cevscpe(scicos_block * block, int flag)
128 ScopeMemory * pScopeMemory = NULL;
131 scoGraphicalObject pShortDraw, pLongDraw;
139 cevscpe_draw(block,&pScopeMemory,1);
146 /* Charging elements */
148 scoRetrieveScopeMemory(block->work,&pScopeMemory);
150 if(scoGetScopeActivation(pScopeMemory) == 1)
153 t = get_scicos_time();
154 if(scoGetPointerScopeWindow(pScopeMemory) == NULL)
156 cevscpe_draw(block,&pScopeMemory,0);
159 scoRefreshDataBoundsX(pScopeMemory,t);
163 for(i = 0 ; i < scoGetNumberOfCurvesBySubwin(pScopeMemory,0) ; i++)
165 if((GetNevIn(block)&(1<<i))==(1<<i))
172 for(i = 0 ; i < nbseg ; i++)
174 pShortDraw = scoGetPointerShortDraw(pScopeMemory,0,tab[i]);
175 pSEGS_FEATURE(pShortDraw)->vx[0] = t;
176 pSEGS_FEATURE(pShortDraw)->vx[1] = t;
177 pSEGS_FEATURE(pShortDraw)->vy[0] = i*0.8/nbseg;
178 pSEGS_FEATURE(pShortDraw)->vy[1] = (i+1)*0.8/nbseg;
179 pSEGS_FEATURE(pShortDraw)->Nbr1 = 2;
180 pSEGS_FEATURE(pShortDraw)->Nbr2 = 2;
182 /*End of Not Factorize*/
183 scoDrawScopeAmplitudeTimeStyle(pScopeMemory,t);
191 scoRetrieveScopeMemory(block->work, &pScopeMemory);
192 if(scoGetScopeActivation(pScopeMemory) == 1)
194 /* sciSetUsedWindow(scoGetWindowID(pScopeMemory)); */
195 /* Check if figure is still opened, otherwise, don't try to destroy it again. */
196 if(scoGetPointerScopeWindow(pScopeMemory) != NULL)
198 for(i = 0 ; i < scoGetNumberOfCurvesBySubwin(pScopeMemory,0) ; i++)
200 /* maybe a bug here in the last argument of the following instruction (see tab[i]) */
201 pLongDraw = scoGetPointerLongDraw(pScopeMemory,0,i);
202 forceRedraw(pLongDraw);
206 /* pShortDraw = sciGetCurrentFigure(); */
207 pShortDraw = scoGetPointerScopeWindow(pScopeMemory);
208 clearUserData(pShortDraw);
209 /* pFIGURE_FEATURE(pShortDraw)->user_data = NULL; */
210 /* pFIGURE_FEATURE(pShortDraw)->size_of_user_data = 0; */
211 /* restore double buffering */
213 sciSetJavaUseSingleBuffer(pShortDraw, FALSE);
217 scoFreeScopeMemory(block->work,&pScopeMemory);
222 /*--------------------------------------------------------------------------*/