]> rtime.felk.cvut.cz Git - orte.git/blob - orte/contrib/shape/MulticlipForm.ui.h
7b4817948ef097734104079b9338c673a43afe1b
[orte.git] / orte / contrib / shape / MulticlipForm.ui.h
1 /****************************************************************************
2 ** ui.h extension file, included from the uic-generated form implementation.
3 **
4 ** If you wish to add, delete or rename slots use Qt Designer which will
5 ** update this file, preserving your code. Create an init() slot in place of
6 ** a constructor, and a destroy() slot in place of a destructor.
7 *****************************************************************************/
8 #include <orte.h>
9 #include <qwidget.h>
10 Subscriber *tabSub[50];
11 int NSubscriber;
12 Publisher *tabPub[50];
13 int NPublisher;
14 int np,ns;
15
16 void MulticlipForm::init()
17 {
18         memset(tabSub,0,sizeof(tabSub));
19         memset(tabPub,0,sizeof(tabPub));
20         NPublisher=0;
21         NSubscriber=0;
22         np=ns=1;
23         QTimer *timer = new QTimer(this);
24         connect( timer, SIGNAL(timeout()), SLOT(Timer()));
25         timer->start( 500, FALSE );
26 }
27
28
29 void MulticlipForm::addPublisher()
30 {
31         PublishersListBox->insertItem( QString::number(np), 0 );
32         GotoP();
33         NPublisher++;
34 }
35
36
37
38 void MulticlipForm::deletePublisher()
39 {
40         QString  text=PublishersListBox->currentText();
41         if(PublishersListBox->currentItem()!=-1 && !text.isEmpty()){
42                 int pub;
43                 pub=NPublisher-1-PublishersListBox->currentItem() ;
44                 PublishersListBox->removeItem( PublishersListBox->currentItem() );
45                 tabPub[pub]->Destroy();
46                 delete(tabPub[pub]);
47                 for(int i=pub;i+1<NPublisher;i++) tabPub[i]=tabPub[i+1];
48                 tabPub[NPublisher]=NULL;
49                 NPublisher--;
50         }
51 }
52
53
54 void MulticlipForm::GotoP(  )
55 {
56     QString name = QString::number(np);
57         np++;
58     int shap=ShapeP->currentItem();
59     int color=ColorP->currentItem();
60     int strength=0;
61    tabPub[NPublisher]=new Publisher();
62    tabPub[NPublisher]->Create(name,shap,color,strength);
63 }
64
65
66
67 void MulticlipForm::closeEvent( QCloseEvent *e )
68 {
69         int i;
70     for(i=0;i<NPublisher;i++){
71          tabPub[i]->Destroy();
72          delete(tabPub[i]);
73      }
74     for(i=0;i<NSubscriber;i++){
75          tabSub[i]->Destroy();
76          delete(tabSub[i]);
77      }
78 e->accept();
79 }
80
81 void rcvCallBack(ORTERcvInfo *rcvInfo,u_char status)
82 {
83         QRect rect;
84         int a,b,c,d;
85         char *topic,*type;
86         int top=0,typ=0;
87         switch (status) {
88                 case 0:  //Issue
89                         sscanf((char*)rcvInfo->data,"%i %i %i %i",&a,&b,&c,&d);
90                         rect.setCoords(a,b,c,d);
91                         topic=(char *)rcvInfo->subsTopic;
92                         type=(char *)rcvInfo->subsTypeName;
93                         if(strcmp(topic,"Ellipse")==0)top=0;
94                         if(strcmp(topic,"Rectangle")==0)top=1;
95                         if(strcmp(topic,"Triangle")==0)top=2;
96                         if(strcmp(type,"Blue")==0)typ=0;
97                         if(strcmp(type,"Green")==0)typ=1;
98                         if(strcmp(type,"Red")==0)typ=2;
99                         if(strcmp(type,"Black")==0)typ=3;
100
101                         for(int i=0;i<NSubscriber;i++){
102                         if(tabSub[i]->topS==top && tabSub[i]->typS==typ){
103                                 (tabSub[i]->m_mainFrm)->setCaption(tabSub[i]->strTitle);
104                                 (tabSub[i]->m_mainFrm)->SetShapeRect(rect);
105                         }
106                 }
107                 break;
108                 case 1:  //Data
109                         for(int i=0;i<NSubscriber;i++){
110                                 int dead=0;
111                                 if(NPublisher!=0){
112                                         for(int j=0;j<NPublisher;j++){
113                                                 if(tabSub[i]->topS!=tabPub[j]->top || tabSub[i]->typS!=tabPub[j]->typ){
114                                                 dead++;
115                                                 }
116                                         }
117                                 }
118                          if(NPublisher==0 || dead==NPublisher){
119                                 QString name=tabSub[i]->strTitle+" deadline ";
120                                 (tabSub[i]->m_mainFrm)->setCaption(name);
121                         }
122                 }
123                 break;
124         }
125 }
126
127 void MulticlipForm::GotoS(  )
128 {
129     QString name =QString::number(ns);
130         ns++;
131     int shap=ShapeS->currentItem();
132     int color=ColorS->currentItem();
133         QString topic;
134         QString type;
135
136 switch(shap)
137         {
138         case RECTANGLE:
139                 topic="Rectangle";
140                 break;
141         case ELLIPSE:
142                 topic="Ellipse";
143                 break;
144         case TRIANGLE:
145                 topic="Triangle";
146                 break;
147         }
148
149         switch(color)
150         {
151         case BLUE:
152                 type="Blue";
153                 break;
154         case GREEN:
155                 type="Green";
156                 break;
157         case RED:
158                 type="Red";
159                 break;
160         case BLACK:
161                 type="Black";
162                 break;
163         }
164 NtpTime minimumSeparation,deadline;
165 int h_sub;
166    tabSub[NSubscriber]=new Subscriber();
167    tabSub[NSubscriber]->Create(name,shap,color);
168 ORTEAppCreate(&(tabSub[NSubscriber]->app));
169   NtpTimeAssembFromMs(minimumSeparation,0,0);
170   NtpTimeAssembFromMs(deadline, 5, 0);
171  h_sub=ORTEAppSubsAdd(tabSub[NSubscriber]->app,topic,type, &minimumSeparation,&deadline,rcvCallBack);
172 }
173
174 void MulticlipForm::addSubscriber()
175 {
176         
177         SubscribersListBox->insertItem( QString::number(ns), 0 );
178         GotoS();
179         NSubscriber++;
180 }
181
182
183 void MulticlipForm::deleteSubscriber()
184 {
185 QString  text=SubscribersListBox->currentText();
186         if(SubscribersListBox->currentItem()!=-1 && !text.isEmpty()){
187                 int pub;
188                 pub=NSubscriber-1-SubscribersListBox->currentItem() ;
189                 SubscribersListBox->removeItem( SubscribersListBox->currentItem() );
190                 tabSub[pub]->Destroy();
191                 delete(tabSub[pub]);
192                 for(int i=pub;i+1<NSubscriber;i++) tabSub[i]=tabSub[i+1];
193                 tabSub[NSubscriber]=NULL;
194                 NSubscriber--;
195         }
196 }
197
198
199
200 void MulticlipForm::keyPressEvent( QKeyEvent *e )
201 {    
202     if(Qt::Key_Delete==e->key() ) {
203                 if( focusWidget ()==PublishersListBox)deletePublisher();
204                 if( focusWidget ()==SubscribersListBox)deleteSubscriber();
205     }
206 }
207
208
209
210 void MulticlipForm::Timer()
211 {
212         int i;
213         for(i=0;i<NPublisher;i++){
214                 if((tabPub[i]->m_mainFrm)->getClose()==1){
215                         PublishersListBox->setCurrentItem (NPublisher-1-i);
216                         deletePublisher();
217                 }
218         }
219         for(i=0;i<NSubscriber;i++){
220                 if((tabSub[i]->m_mainFrm)->getClose()==1){
221                         SubscribersListBox->setCurrentItem (NSubscriber-1-i);
222                         deleteSubscriber();
223                 }
224         }
225 }