BoxChannelShape.cpp
gehe zur Dokumentation dieser Datei
00001 // -*-C++ -*-
00134 #include "BoxChannelShape.h"
00135 //#include "MutApp.h"
00136 //#include "MutIcon.h"
00137 //#include "MutRouteWnd.h"
00138 //#include "InputDevDlg.h"
00139 //#include "Device.h"
00140 #include "OutputDeviceShape.h"
00141 #include "BoxDlg.h"
00142 
00143 
00144 MutIcon& MutBoxChannelShape::GetMutIcon()
00145 {
00146 
00147         DEBUGLOG (other, _T("Checking icons"));
00148 
00149         wxASSERT(ActiveChannelBitmap.IsOk () && PassiveChannelBitmap.IsOk ());
00150 
00151         if (route && (route -> GetActive())) {
00152                 return ActiveChannelBitmap;
00153         } else {
00154                 return PassiveChannelBitmap;
00155         }
00156 }
00157 
00158 void MutBoxChannelShape::SetInput(MutInputDeviceShape * device) 
00159 {
00160         input = device;
00161 }
00162 
00163 void MutBoxChannelShape::SetOutput(MutOutputDeviceShape * device, 
00164                                    bool changeRoute) 
00165 {
00166         DEBUGLOG(routing,_T("Setting output of %p to %p (change route %p = %d)"),this,device,route, changeRoute);
00167         if (changeRoute) {
00168                 wxASSERT(route);
00169                 OutDevice * dev = device ? device -> GetDevice() : NULL;
00170                 route -> SetOutDevice(dev);
00171         }
00172 #ifdef DEBUG
00173         if (device && route) {
00174                 wxASSERT(device->GetDevice() == route->GetOutDevice());
00175         }
00176 #endif
00177         output = device;
00178 }
00179 
00180 
00181 void MutBoxChannelShape::AddPossibleOutput(MutOutputDeviceShape * device) {
00182         OutDevice * out;
00183         if (route) out = route->GetOutDevice(); else out = NULL;
00184         if (!out) return;
00185         if (device->GetDevice() == out) {
00186                 SetOutput(device);
00187                 device->AddRoute(route);
00188         }
00189 }
00190 
00191 
00192 void MutBoxChannelShape::DrawLines(wxDC & dc, const wxPoint & parentPosition) const
00193 {
00194         wxRect m_rect = GetRect();
00195         m_rect.x += parentPosition.x;
00196         m_rect.y += parentPosition.y;
00197         
00198         wxPoint center(m_rect.x + m_rect.width/2, m_rect.y + m_rect.height/2);
00199 
00200         if (input) {
00201                 wxRect rect = input->GetRect();
00202                 wxPoint p2(center.x, 
00203                            m_rect.y + Icon.GetHeight()/2);
00204                 wxPoint p1(input->GetPerimeterPoint(wxPoint(rect.x+rect.width/2,rect.y + rect.height/2), p2));
00205                 p2 = GetPerimeterPoint(p2,p1,parentPosition);
00206                 input -> LineTo(dc,p1);
00207                 dc.DrawLine(p1,p2);
00208                 dc.DrawLine(p2,center);
00209         }
00210 
00211         if (output) {
00212 #ifdef DEBUG
00213                 DEBUGLOG (other, _T("Drawing output line to device %x"),output->GetDevice());
00214                 wxASSERT(output->GetDevice());
00215                 DEBUGLOG (other, _T("Lines for device:\n%s"), output->GetDevice()->TowxString().c_str());
00216 #endif
00217                 wxRect rect = output->GetRect();
00218                 DEBUGLOG (other, _T("Output rect: (%d,%d) -- (%d,%d)"),rect.x,rect.y,rect.x+rect.width, rect.y+rect.height);
00219                 wxPoint p2(center.x, m_rect.y + Icon.GetHeight()/2);
00220                 wxPoint p1(output->GetPerimeterPoint(wxPoint(rect.x+rect.width/2,rect.y + rect.height/2), p2));
00221                 p2 = GetPerimeterPoint(p2,p1,parentPosition);
00222                 output -> LineTo(dc,p1);
00223                 dc.DrawLine(p1,p2);
00224                 dc.DrawLine(p2,center);
00225         }
00226 }
00227 
00228 wxPoint MutBoxChannelShape::GetPerimeterPoint(const wxPoint &i,const wxPoint &o, const wxPoint & parentPosition) const {
00229         wxRect r = GetRect();
00230         DEBUGLOG (other, _T("Rect: (%d,%d) -- (%d,%d)"),r.x,r.y,r.x+r.width,r.y+r.height);
00231         DEBUGLOG (other, _T("Points: i = (%d,%d), o = (%d, %d)"),i.x,i.y,o.x,o.y);
00232 //      wxRect ir = GetIconRect();
00233 
00234         r.x += parentPosition.x;
00235         r.y += parentPosition.y;
00236 
00237 #ifdef DEBUG
00238         wxASSERT(r.Contains(i));
00239 #endif
00240         wxPoint p(r.x + r.width/2, r.y + r.height/2);
00241                 
00242         if (r.x + r.width < o.x) {
00243                 p.x = r.x + r.width;
00244         } else if (p.x > o.x) {
00245                 p.x = r.x;
00246         } else p = o;
00247         
00248         return p;
00249 }
00250 
00251 void MutBoxChannelShape::CreateRoutePanel(MutBoxChannelShape * channel, MutRouteWnd * parentwin, wxWindow * routeWindow, int selectBox) {
00252         wxSizer * routeSizer = routeWindow->GetSizer();
00253         if (!routeSizer) UNREACHABLECT(MutBoxChannelShape);
00254         
00255         InputFilterPanel * inputfilter = new InputFilterPanel(routeWindow);
00256         MutBoxChannelShape::InitializeInputFilter(inputfilter,parentwin,channel);
00257         
00258         RoutePanel * routePanel = new RoutePanel(routeWindow);
00259         MutBoxChannelShape::InitializeRoute(routePanel,parentwin,channel,selectBox);
00260         
00261         OutputFilterPanel * outputfilter = new OutputFilterPanel(routeWindow);
00262         MutBoxChannelShape::InitializeOutputFilter(outputfilter,parentwin,channel);
00263         
00264         routePanel->SetInput(inputfilter);
00265         routePanel->SetOutput(outputfilter);
00266         routePanel->SetChannel(channel);
00267         
00268         RouteRemoveButton * removeButton = new RouteRemoveButton(routePanel,routeWindow);
00269         
00270         routeSizer->Add(inputfilter,0,wxEXPAND);
00271         routeSizer->Add(routePanel,0,wxEXPAND);
00272         routeSizer->Add(outputfilter,0,wxEXPAND);
00273         routeSizer->Add(removeButton,0,wxALL|wxALIGN_TOP|wxALIGN_CENTER_HORIZONTAL,5);
00274         removeButton->EnableRoute();    
00275 }
00276 
00277 
00278 
00279 void MutBoxChannelShape::InitializeInputFilter(InputFilterPanel * panel, 
00280                                                MutRouteWnd * par,
00281                                                MutBoxChannelShape * shape)
00282 {
00283         wxASSERT(par);
00284         wxChoicebook * choiceBook = panel->GetInputDeviceBook();
00285         
00286         MutInputDeviceShape * input;
00287         if (shape)
00288                 input = shape->input;
00289         else
00290                 input = NULL;
00291         Route * route;
00292         if (shape)
00293                 route = shape->route;
00294         else
00295                 route = NULL;
00296         
00297         panel->AddPage(new wxPanel(choiceBook),_("No input device"),!input,NULL);
00298         wxSizer *inputs = par->GetInputDevices();
00299         const wxSizerItemList &list = inputs->GetChildren();
00300         for (wxSizerItemList::const_iterator i = list.begin(); 
00301              i != (list.end()); i++) {
00302                 MutInputDeviceShape * device = dynamic_cast<MutInputDeviceShape *> ((*i)->GetWindow());
00303                 
00304                 if (!device) continue;
00305                 wxPanel * devicePanel = device -> GetInputFilterPanel(choiceBook, route);
00306                 panel -> AddPage(devicePanel, device->GetLabel(), input == device, device);
00307         }
00308 }
00309 
00310 void MutBoxChannelShape::InitializeRoute(RoutePanel * panel, 
00311                                          MutRouteWnd * par,
00312                                          MutBoxChannelShape * shape,
00313                                          int selectBox)
00314 {
00315         wxASSERT(par);
00316         wxASSERT(panel);
00317         
00318         if (!par || !panel) return;
00319         Route * route;
00320         if (shape)
00321                 route = shape->route;
00322         else
00323                 route = NULL;
00324         
00325         if (route)
00326                 panel->SetActive(route->GetActive());
00327         else
00328                 panel->SetActive(true);
00329         
00330         wxSizer *boxes = par->GetBoxes();
00331 
00332         
00333         bool found = false;
00334         
00335         const wxSizerItemList &list = boxes->GetChildren();
00336         for (wxSizerItemList::const_iterator i = list.begin(); 
00337              i != (list.end()); i++) {
00338                 MutBoxShape * box = dynamic_cast<MutBoxShape *> ((*i)->GetWindow());
00339                 if (box) {
00340                         bool select = box->GetBoxId() == selectBox;
00341                         panel->AddBox(box, select);
00342                         found |= select;
00343                 }
00344         }
00345 
00346         if (!found)
00347                 panel->AddBox(NULL, true);
00348 }
00349 
00350 void MutBoxChannelShape::InitializeOutputFilter(OutputFilterPanel * panel, 
00351                                                MutRouteWnd * par,
00352                                                MutBoxChannelShape * shape) {
00353         wxASSERT(par);
00354         wxASSERT(panel);
00355         if (!par || !panel) return;
00356 
00357         // parent for child elements
00358         wxChoicebook * choiceBook = panel->GetOutputDeviceBook();
00359         
00360         MutOutputDeviceShape * output;
00361         if (shape)
00362                 output = shape->output;
00363         else
00364                 output = NULL;
00365         Route * route;
00366         if (shape)
00367                 route = shape->route;
00368         else
00369                 route = NULL;
00370         
00371         panel -> AddPage(new wxPanel(choiceBook), _("No output device"), !output, NULL);
00372         
00373         wxSizer *outputs = par->GetOutputDevices();
00374         const wxSizerItemList &list = outputs->GetChildren();
00375         for (wxSizerItemList::const_iterator i = list.begin(); 
00376              i != (list.end()); i++) {
00377                 MutOutputDeviceShape * device = wxDynamicCast((*i)->GetWindow(),
00378                                                              MutOutputDeviceShape);
00379                 if (!device) continue;
00380                 wxPanel * devicePanel = device -> GetOutputFilterPanel (choiceBook, route);
00381                 panel -> AddPage (devicePanel, device->GetLabel(), output == device, device);
00382         }
00383 }
00384 
00385 void MutBoxChannelShape::ReadPanel(RoutePanel * panel) 
00386 {
00387         wxASSERT(panel);
00388         wxASSERT(route);
00389         if (!panel) return;
00390         if (!route) return;
00391         
00392         if (!panel->IsEnabled()) {
00393                 DetachChannel();
00394                 DeleteSelf();
00395                 return;
00396         }
00397 
00398         DEBUGLOG (dialog, _T("Setting route channel: old: %d; new: %d"),route->GetActive(),panel->GetActive());
00399         route->SetActive(panel->GetActive());
00400         
00401         MutBoxShape * box = panel->GetBox();
00402         if (!box) {
00403                 box = dynamic_cast<MutBoxShape *> (GetParent());
00404                 if (!box) UNREACHABLEC;
00405         } else if (box != GetParent()) {
00409                 MutBoxShape * parent = dynamic_cast<MutBoxShape *> (GetParent());
00410                 parent->Detach(this);
00411                 box->AddChannel(this);
00412                 
00413                 STUBC;
00414                 return;
00415         }
00416         
00417         InputFilterPanel * inputPanel = panel->GetInput();
00418         if (!inputPanel) UNREACHABLEC;
00419         else if (inputPanel && !input) {
00420                 input = inputPanel->GetCurrentSelection();
00421                 if (input) input -> AddRoute(route);
00422         }
00423         wxASSERT(inputPanel);
00424         if (input)
00425                 input->ReadPanel(inputPanel,this);
00426         
00427         OutputFilterPanel * outputPanel = panel->GetOutput();
00428         if (!outputPanel) UNREACHABLEC;
00429         else if (outputPanel && !output) {
00430                 SetOutput(outputPanel->GetCurrentSelection(),true);
00431                 if (output) output->AddRoute(this);
00432         }
00433         if (output)
00434                 output->ReadPanel(outputPanel,this);
00436         Refresh();
00437 }
00438 
00439 void MutBoxChannelShape::Refresh(bool eraseBackground, const wxRect* rect) {
00440         if (!rect) {
00441                 SetIcon(GetMutIcon());
00442         }
00443         MutIconShape::Refresh(eraseBackground,rect);
00444 }
00445 
00446 void MutBoxChannelShape::DetachChannel() {
00447         if (input) input->RemoveRoute(route);
00448         if (output) output->RemoveRoute(route);
00449         delete route;
00450         route = NULL;
00451 }
00452 
00453 
00454 #include "wx/listimpl.cpp"
00455 
00456 WX_DEFINE_LIST (MutBoxChannelShapeList);
00457 
00458 /*
00459  * \}
00460  */

Erzeugt am Sun Aug 21 2011 10:51:55 für Mutabor von doxygen 1.7.4