@@ -38,7 +38,7 @@ Authors: Alex Parent, Jacob Parker
38
38
#include " QCLib/subcircuit.h"
39
39
40
40
using namespace std ;
41
- void QCViewer::setup_gate_button (Gtk::Button* btn, GateIcon *g, vector<Gtk::TargetEntry> &listTargets )
41
+ void QCViewer::setup_gate_button (Gtk::Button* btn, GateIcon *g)
42
42
{
43
43
btn->set_image (*g);
44
44
btn->drag_source_set (listTargets);
@@ -120,15 +120,20 @@ void QCViewer::set_raxis ()
120
120
shared_ptr<Gate> g = c.getSelectedGate ();
121
121
if (g->type != Gate::RGATE) {
122
122
cout << " UNEXPECTED THING HAPPENED!!!! " << __FILE__ << __LINE__ << endl;
123
- return ;
124
- }
125
- RGate::Axis na;
126
- if (btn_RX.get_active ()) na = RGate::X;
127
- else if (btn_RY.get_active ()) na = RGate::Y;
128
- else na = RGate::Z;
129
- if (na != ((RGate*)g.get ())->get_axis ()) {
130
- ((RGate*)g.get ())->set_axis (na);
131
- c.force_redraw ();
123
+ } else {
124
+ shared_ptr<RGate> rg = dynamic_pointer_cast<RGate>(g);
125
+ RGate::Axis na;
126
+ if (btn_RX.get_active ()) {
127
+ na = RGate::X;
128
+ } else if (btn_RY.get_active ()) {
129
+ na = RGate::Y;
130
+ } else {
131
+ na = RGate::Z;
132
+ }
133
+ if (na != rg->get_axis ()) {
134
+ rg->set_axis (na);
135
+ c.force_redraw ();
136
+ }
132
137
}
133
138
}
134
139
@@ -137,22 +142,23 @@ void QCViewer::set_rval ()
137
142
shared_ptr<Gate> g = c.getSelectedGate ();
138
143
if (g->type != Gate::RGATE) {
139
144
cout << " UNEXPECTED THING HAPPENED!!!! " << __FILE__ << __LINE__ << endl;
140
- return ;
141
- }
142
- istringstream ss (m_RValEntry.get_text ());
143
- float nr;
144
- ss >> nr;
145
- if (ss.fail ()) {
146
- stringstream ss;
147
- ss << ((RGate*)g.get ())->get_rotVal ();
148
- m_RValEntry.set_text (ss.str ());
149
- Gtk::MessageDialog dialog (*this , " Error" );
150
- dialog.set_secondary_text (" Rotation factor must be a floating point number." );
151
- dialog.run ();
152
- return ;
145
+ } else {
146
+ shared_ptr<RGate> rg = dynamic_pointer_cast<RGate>(g);
147
+ istringstream ss (m_RValEntry.get_text ());
148
+ float nr;
149
+ ss >> nr;
150
+ if (ss.fail ()) {
151
+ stringstream ss;
152
+ ss << rg->get_rotVal ();
153
+ m_RValEntry.set_text (ss.str ());
154
+ Gtk::MessageDialog dialog (*this , " Error" );
155
+ dialog.set_secondary_text (" Rotation factor must be a floating point number." );
156
+ dialog.run ();
157
+ return ;
158
+ }
159
+ rg->set_rotVal (nr);
160
+ c.force_redraw ();
153
161
}
154
- ((RGate*)g.get ())->set_rotVal (nr);
155
- c.force_redraw ();
156
162
}
157
163
158
164
void QCViewer::on_menu_about ()
@@ -432,8 +438,9 @@ void QCViewer::set_selection (vector<Selection> s)
432
438
} else if (selections.size () == 1 ) {
433
439
shared_ptr<Gate> gate = c.getSelectedGate ();
434
440
if (gate != NULL && gate->type == Gate::RGATE) {
441
+ shared_ptr<RGate> rg = dynamic_pointer_cast<RGate>(gate);
435
442
m_RGateEditFrame.show ();
436
- switch (((RGate*)gate. get ()) ->get_axis ()) {
443
+ switch (rg ->get_axis ()) {
437
444
case RGate::X:
438
445
btn_RX.set_active ();
439
446
break ;
@@ -445,7 +452,7 @@ void QCViewer::set_selection (vector<Selection> s)
445
452
break ;
446
453
}
447
454
stringstream ss;
448
- ss << ((RGate*)gate. get ()) ->get_rotVal ();
455
+ ss << rg ->get_rotVal ();
449
456
m_RValEntry.set_text (ss.str ());
450
457
} else {
451
458
m_RGateEditFrame.hide ();
@@ -495,7 +502,8 @@ void QCViewer::set_subcircuit_name()
495
502
{
496
503
shared_ptr<Gate> g = c.getSelectedGate ();
497
504
if (g != NULL && g->type ==Gate::SUBCIRC) {
498
- ((Subcircuit*)g.get ())->setName (m_SubcircNameEntry.get_text ());
505
+ shared_ptr<Subcircuit> sub = dynamic_pointer_cast<Subcircuit>(g);
506
+ sub->setName (m_SubcircNameEntry.get_text ());
499
507
c.force_redraw ();
500
508
}
501
509
}
@@ -505,7 +513,8 @@ void QCViewer::expand_subcirc()
505
513
{
506
514
shared_ptr<Gate> g = c.getSelectedGate ();
507
515
if (g != NULL && g->type ==Gate::SUBCIRC) {
508
- ((Subcircuit*)g.get ())->expand = !((Subcircuit*)g.get ())->expand ;
516
+ shared_ptr<Subcircuit> sub = dynamic_pointer_cast<Subcircuit>(g);
517
+ sub->expand = !sub->expand ;
509
518
c.force_redraw ();
510
519
}
511
520
}
@@ -519,7 +528,8 @@ void QCViewer::unroll_subcirc()
519
528
{
520
529
shared_ptr<Gate> g = c.getSelectedGate ();
521
530
if (g != NULL && g->type ==Gate::SUBCIRC) {
522
- ((Subcircuit*)g.get ())->unroll = !((Subcircuit*)g.get ())->unroll ;
531
+ shared_ptr<Subcircuit> sub = dynamic_pointer_cast<Subcircuit>(g);
532
+ sub->unroll = !sub->unroll ;
523
533
c.force_redraw ();
524
534
}
525
535
}
@@ -770,7 +780,7 @@ void QCViewer::setup_gate_icons()
770
780
}
771
781
for (unsigned int i = 0 , y = 0 , x = 0 ; i < gate_icons.size (); i++) {
772
782
gate_buttons.push_back (manage (new Gtk::Button ()));
773
- setup_gate_button (gate_buttons[i], gate_icons[i], listTargets );
783
+ setup_gate_button (gate_buttons[i], gate_icons[i]);
774
784
m_GatesTable.attach (*gate_buttons[i],x,x+1 ,y,y+1 );
775
785
x++;
776
786
if (x > 3 ) {
@@ -804,4 +814,3 @@ void QCViewer::add_stock_item(const Glib::RefPtr<Gtk::IconFactory>& factory, con
804
814
Gtk::Stock::add (Gtk::StockItem (stock_id, label));
805
815
}
806
816
}
807
-
0 commit comments