GUI can now export graph to EPS.
3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
19 #include "graph_displayer_canvas.h"
23 bool GraphDisplayerCanvas::on_expose_event(GdkEventExpose *event)
25 Gnome::Canvas::CanvasAA::on_expose_event(event);
31 void GraphDisplayerCanvas::changeEditorialTool(int newtool)
33 if(actual_tool!=newtool)
36 actual_handler.disconnect();
42 GdkEvent * generated=new GdkEvent();
43 generated->type=GDK_BUTTON_RELEASE;
44 generated->button.button=3;
45 createEdgeEventHandler(generated);
67 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
71 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createNodeEventHandler), false);
75 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createEdgeEventHandler), false);
79 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::eraserEventHandler), false);
84 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::mapEditEventHandler), false);
93 int GraphDisplayerCanvas::getActualTool()
98 bool GraphDisplayerCanvas::scrollEventHandler(GdkEvent* e)
101 if(e->type==GDK_SCROLL)
104 //pointer shows this win point before zoom
105 XY win_coord(((GdkEventScroll*)e)->x, ((GdkEventScroll*)e)->y);
107 //the original scroll settings
108 int scroll_offset_x, scroll_offset_y;
109 get_scroll_offsets(scroll_offset_x, scroll_offset_y);
111 //pointer shows this canvas point before zoom
113 window_to_world(win_coord.x, win_coord.y, canvas_coord.x, canvas_coord.y);
115 if(((GdkEventScroll*)e)->direction) //IN
124 //pointer shows this window point after zoom
126 world_to_window(canvas_coord.x, canvas_coord.y, post_win_coord.x, post_win_coord.y);
128 //we have to add the difference between new and old window point to original scroll offset
129 scroll_to(scroll_offset_x+(int)(post_win_coord.x-win_coord.x),scroll_offset_y+(int)(post_win_coord.y-win_coord.y));
131 //no other eventhandler is needed
137 bool GraphDisplayerCanvas::moveEventHandler(GdkEvent* e)
139 static Gnome::Canvas::Text *coord_text = 0;
142 case GDK_BUTTON_PRESS:
143 //we mark the location of the event to be able to calculate parameters of dragging
144 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
146 active_item=(get_item_at(clicked_x, clicked_y));
148 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
150 if(nodesmap[i]==active_item)
155 isbutton=e->button.button;
157 case GDK_BUTTON_RELEASE:
167 case GDK_MOTION_NOTIFY:
168 //we only have to do sg. if the mouse button is pressed AND the click was on a node that was found in the set of nodes
169 if(active_node!=INVALID)
171 (mytab.mapstorage).modified = true;
173 //new coordinates will be the old values,
174 //because the item will be moved to the
175 //new coordinate therefore the new movement
176 //has to be calculated from here
180 window_to_world (e->motion.x, e->motion.y, new_x, new_y);
182 double dx=new_x-clicked_x;
183 double dy=new_y-clicked_y;
190 // reposition the coordinates text
191 std::ostringstream ostr;
193 (mytab.mapstorage).coords[active_node].x << ", " <<
194 (mytab.mapstorage).coords[active_node].y << ")";
196 (nodesmap[active_node]->property_x2().get_value() -
197 nodesmap[active_node]->property_x1().get_value()) / 2.0;
200 coord_text->property_text().set_value(ostr.str());
201 coord_text->property_x().set_value((mytab.mapstorage).coords[active_node].x +
203 coord_text->property_y().set_value((mytab.mapstorage).coords[active_node].y -
208 coord_text = new Gnome::Canvas::Text(
210 (mytab.mapstorage).coords[active_node].x + radius,
211 (mytab.mapstorage).coords[active_node].y - radius,
213 coord_text->property_fill_color().set_value("black");
214 coord_text->property_anchor().set_value(Gtk::ANCHOR_SOUTH_WEST);
225 XY GraphDisplayerCanvas::calcArrowPos(XY moved_node_1, XY moved_node_2, XY fix_node, XY old_arrow_pos, int move_code)
230 return XY((moved_node_2.x + fix_node.x) / 2.0, (moved_node_2.y + fix_node.y) / 2.0);
233 return old_arrow_pos;
237 //////////////////////////////////////////////////////////////////////////////////////////////////////
238 /////////// keeps shape-with scalar multiplication - version 2.
239 //////////////////////////////////////////////////////////////////////////////////////////////////////
241 //old vector from one to the other node - a
242 XY a_v(moved_node_1.x-fix_node.x,moved_node_1.y-fix_node.y);
243 //new vector from one to the other node - b
244 XY b_v(moved_node_2.x-fix_node.x,moved_node_2.y-fix_node.y);
246 double absa=sqrt(a_v.normSquare());
247 double absb=sqrt(b_v.normSquare());
249 if ((absa == 0.0) || (absb == 0.0))
251 return old_arrow_pos;
255 //old vector from one node to the breakpoint - c
256 XY c_v(old_arrow_pos.x-fix_node.x,old_arrow_pos.y-fix_node.y);
258 //unit vector with the same direction to a_v
259 XY a_v_u(a_v.x/absa,a_v.y/absa);
261 //normal vector of unit vector with the same direction to a_v
262 XY a_v_u_n(((-1)*a_v_u.y),a_v_u.x);
264 //unit vector with the same direction to b_v
265 XY b_v_u(b_v.x/absb,b_v.y/absb);
267 //normal vector of unit vector with the same direction to b_v
268 XY b_v_u_n(((-1)*b_v_u.y),b_v_u.x);
270 //vector c in a_v_u and a_v_u_n co-ordinate system
271 XY c_a(c_v*a_v_u,c_v*a_v_u_n);
273 //new vector from one node to the breakpoint - d - we have to calculate this one
274 XY d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n);
276 return XY(d_v.x+fix_node.x,d_v.y+fix_node.y);
286 bool GraphDisplayerCanvas::createNodeEventHandler(GdkEvent* e)
291 case GDK_MOTION_NOTIFY:
293 GdkEvent * generated=new GdkEvent();
294 generated->motion.x=e->motion.x;
295 generated->motion.y=e->motion.y;
296 generated->type=GDK_MOTION_NOTIFY;
297 moveEventHandler(generated);
301 case GDK_BUTTON_RELEASE:
302 (mytab.mapstorage).modified = true;
308 active_node=(mytab.mapstorage).graph.addNode();
310 //initiating values corresponding to new node in maps
312 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
314 // update coordinates
315 (mytab.mapstorage).coords.set(active_node, XY(clicked_x, clicked_y));
317 // update all other maps
318 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
319 (mytab.mapstorage).nodemap_storage.begin(); it !=
320 (mytab.mapstorage).nodemap_storage.end(); ++it)
322 if ((it->first != "coordinates_x") &&
323 (it->first != "coordinates_y"))
325 (*(it->second))[active_node] =
326 (mytab.mapstorage).nodemap_default[it->first];
329 // increment the id map's default value
330 (mytab.mapstorage).nodemap_default["label"] += 1.0;
332 nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph,
333 clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
334 active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]);
335 *(nodesmap[active_node]) <<
336 Gnome::Canvas::Properties::fill_color("blue");
337 *(nodesmap[active_node]) <<
338 Gnome::Canvas::Properties::outline_color("black");
339 active_item->raise_to_top();
341 (nodesmap[active_node])->show();
343 nodetextmap[active_node]=new Gnome::Canvas::Text(displayed_graph,
344 clicked_x+node_property_defaults[N_RADIUS]+5,
345 clicked_y+node_property_defaults[N_RADIUS]+5, "");
346 nodetextmap[active_node]->property_fill_color().set_value("darkblue");
347 nodetextmap[active_node]->raise_to_top();
349 // mapwin.updateNode(active_node);
350 propertyUpdate(active_node);
363 bool GraphDisplayerCanvas::createEdgeEventHandler(GdkEvent* e)
367 case GDK_BUTTON_PRESS:
368 //in edge creation right button has special meaning
369 if(e->button.button!=3)
371 //there is not yet selected node
372 if(active_node==INVALID)
374 //we mark the location of the event to be able to calculate parameters of dragging
376 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
378 active_item=(get_item_at(clicked_x, clicked_y));
380 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
382 if(nodesmap[i]==active_item)
387 //the clicked item is really a node
388 if(active_node!=INVALID)
390 *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
393 //clicked item was not a node. It could be e.g. edge.
399 //we only have to do sg. if the mouse button
400 // is pressed already once AND the click was
401 // on a node that was found in the set of
402 //nodes, and now we only search for the second
406 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
407 target_item=(get_item_at(clicked_x, clicked_y));
408 Node target_node=INVALID;
409 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
411 if(nodesmap[i]==target_item)
416 //the clicked item is a node, the edge can be drawn
417 if(target_node!=INVALID)
419 (mytab.mapstorage).modified = true;
421 *(nodesmap[target_node]) <<
422 Gnome::Canvas::Properties::fill_color("red");
425 active_edge=(mytab.mapstorage).graph.addEdge(active_node,
429 for (std::map<std::string,
430 Graph::EdgeMap<double>*>::const_iterator it =
431 (mytab.mapstorage).edgemap_storage.begin(); it !=
432 (mytab.mapstorage).edgemap_storage.end(); ++it)
434 (*(it->second))[active_edge] =
435 (mytab.mapstorage).edgemap_default[it->first];
437 // increment the id map's default value
438 (mytab.mapstorage).edgemap_default["label"] += 1.0;
440 if(target_node!=active_node)
442 // set the coordinates of the arrow on the new edge
443 MapStorage& ms = mytab.mapstorage;
444 ms.arrow_pos.set(active_edge,
445 (ms.coords[ms.graph.source(active_edge)] +
446 ms.coords[ms.graph.target(active_edge)])/ 2.0);
449 edgesmap[active_edge]=new BrokenEdge(displayed_graph, active_edge,
454 // set the coordinates of the arrow on the new edge
455 MapStorage& ms = mytab.mapstorage;
456 ms.arrow_pos.set(active_edge,
457 (ms.coords[ms.graph.source(active_edge)] +
461 edgesmap[active_edge]=new LoopEdge(displayed_graph, active_edge,
465 //initializing edge-text as well, to empty string
466 XY text_pos=mytab.mapstorage.arrow_pos[active_edge];
467 text_pos+=(XY(10,10));
469 edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph,
470 text_pos.x, text_pos.y, "");
471 edgetextmap[active_edge]->property_fill_color().set_value(
473 edgetextmap[active_edge]->raise_to_top();
475 propertyUpdate(active_edge);
477 //clicked item was not a node. it could be an e.g. edge. we do not
478 //deal with it furthermore.
486 case GDK_BUTTON_RELEASE:
488 //we clear settings in two cases
489 //1: the edge is ready (target_item has valid value)
490 //2: the edge creation is cancelled with right button
491 if((target_item)||(e->button.button==3))
495 propertyUpdate(active_node,N_COLOR);
500 propertyUpdate((mytab.mapstorage).graph.target(active_edge),N_COLOR);
513 bool GraphDisplayerCanvas::eraserEventHandler(GdkEvent* e)
517 case GDK_BUTTON_PRESS:
518 //finding the clicked items
519 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
520 active_item=(get_item_at(clicked_x, clicked_y));
524 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
526 if(nodesmap[i]==active_item)
532 if(active_node==INVALID)
534 for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
536 if(edgesmap[i]->getLine()==active_item)
543 // return if the clicked object is neither an edge nor a node
544 if (active_edge == INVALID) return false;
546 //recolor activated item
549 *active_item << Gnome::Canvas::Properties::fill_color("red");
553 case GDK_BUTTON_RELEASE:
554 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
557 //the cursor was not moved since pressing it
558 if( active_item == ( get_item_at (clicked_x, clicked_y) ) )
561 if(active_node!=INVALID)
563 (mytab.mapstorage).modified = true;
565 std::set<Graph::Edge> edges_to_delete;
567 for(OutEdgeIt e((mytab.mapstorage).graph,active_node);e!=INVALID;++e)
569 edges_to_delete.insert(e);
572 for(InEdgeIt e((mytab.mapstorage).graph,active_node);e!=INVALID;++e)
574 edges_to_delete.insert(e);
577 //deleting collected edges
578 for(std::set<Graph::Edge>::iterator
579 edge_set_it=edges_to_delete.begin();
580 edge_set_it!=edges_to_delete.end();
583 deleteItem(*edge_set_it);
585 deleteItem(active_node);
587 //a simple edge was chosen
588 else if (active_edge != INVALID)
590 deleteItem(active_edge);
593 //pointer was moved, deletion is cancelled
596 if(active_node!=INVALID)
598 *active_item << Gnome::Canvas::Properties::fill_color("blue");
600 else if (active_edge != INVALID)
602 *active_item << Gnome::Canvas::Properties::fill_color("green");
612 case GDK_MOTION_NOTIFY:
621 bool GraphDisplayerCanvas::mapEditEventHandler(GdkEvent* e)
623 if(actual_tool==MAP_EDIT)
627 case GDK_BUTTON_PRESS:
629 //for determine, whether it was an edge
630 Edge clicked_edge=INVALID;
631 //for determine, whether it was a node
632 Node clicked_node=INVALID;
634 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
635 active_item=(get_item_at(clicked_x, clicked_y));
637 //find the activated item between text of nodes
638 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
640 //at the same time only one can be active
641 if(nodetextmap[i]==active_item)
647 //if there was not, search for it between nodes
648 if(clicked_node==INVALID)
650 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
652 //at the same time only one can be active
653 if(nodesmap[i]==active_item)
660 if(clicked_node==INVALID)
662 //find the activated item between texts
663 for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
665 //at the same time only one can be active
666 if(edgetextmap[i]==active_item)
672 //if it was not between texts, search for it between edges
673 if(clicked_edge==INVALID)
675 for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
677 //at the same time only one can be active
678 if((edgesmap[i]->getLine())==active_item)
686 //if it was really a node...
687 if(clicked_node!=INVALID)
689 // the id map is not editable
690 if (nodemap_to_edit == "label") return 0;
692 //and there is activated map
693 if(nodetextmap[clicked_node]->property_text().get_value()!="")
695 //activate the general variable for it
696 active_node=clicked_node;
699 Gtk::Dialog dialog("Edit value", true);
700 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
701 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
702 Gtk::VBox* vbox = dialog.get_vbox();
703 Gtk::SpinButton spin(0.0, 4);
704 spin.set_increments(1.0, 10.0);
705 spin.set_range(-1000000.0, 1000000.0);
706 spin.set_numeric(true);
707 spin.set_value(atof(nodetextmap[active_node]->property_text().get_value().c_str()));
710 switch (dialog.run())
712 case Gtk::RESPONSE_NONE:
713 case Gtk::RESPONSE_CANCEL:
715 case Gtk::RESPONSE_ACCEPT:
716 double new_value = spin.get_value();
717 (*(mytab.mapstorage).nodemap_storage[nodemap_to_edit])[active_node] =
719 std::ostringstream ostr;
721 nodetextmap[active_node]->property_text().set_value(ostr.str());
722 //mapwin.updateNode(active_node);
723 //mapwin.updateNode(Node(INVALID));
724 propertyUpdate(Node(INVALID));
729 //if it was really an edge...
730 if(clicked_edge!=INVALID)
732 // the id map is not editable
733 if (edgemap_to_edit == "label") return 0;
735 //and there is activated map
736 if(edgetextmap[clicked_edge]->property_text().get_value()!="")
738 //activate the general variable for it
739 active_edge=clicked_edge;
742 Gtk::Dialog dialog("Edit value", true);
743 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
744 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
745 Gtk::VBox* vbox = dialog.get_vbox();
746 Gtk::SpinButton spin(0.0, 4);
747 spin.set_increments(1.0, 10.0);
748 spin.set_range(-1000000.0, 1000000.0);
749 spin.set_numeric(true);
750 spin.set_value(atof(edgetextmap[active_edge]->property_text().get_value().c_str()));
753 switch (dialog.run())
755 case Gtk::RESPONSE_NONE:
756 case Gtk::RESPONSE_CANCEL:
758 case Gtk::RESPONSE_ACCEPT:
759 double new_value = spin.get_value();
760 (*(mytab.mapstorage).edgemap_storage[edgemap_to_edit])[active_edge] =
762 std::ostringstream ostr;
764 edgetextmap[active_edge]->property_text().set_value(
766 //mapwin.updateEdge(active_edge);
767 // mapwin.updateEdge(Edge(INVALID));
768 propertyUpdate(Edge(INVALID));
781 void GraphDisplayerCanvas::deleteItem(Node node_to_delete)
783 delete(nodetextmap[node_to_delete]);
784 delete(nodesmap[node_to_delete]);
785 (mytab.mapstorage).graph.erase(node_to_delete);
788 void GraphDisplayerCanvas::deleteItem(Edge edge_to_delete)
790 delete(edgetextmap[edge_to_delete]);
791 delete(edgesmap[edge_to_delete]);
792 (mytab.mapstorage).graph.erase(edge_to_delete);
795 void GraphDisplayerCanvas::textReposition(XY new_place)
797 new_place+=(XY(10,10));
798 edgetextmap[forming_edge]->property_x().set_value(new_place.x);
799 edgetextmap[forming_edge]->property_y().set_value(new_place.y);
802 void GraphDisplayerCanvas::toggleEdgeActivity(EdgeBase* active_bre, bool on)
806 if(forming_edge!=INVALID)
808 std::cerr << "ERROR!!!! Valid edge found!" << std::endl;
812 for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
814 if(edgesmap[i]==active_bre)
823 if(forming_edge!=INVALID)
825 forming_edge=INVALID;
829 std::cerr << "ERROR!!!! Invalid edge found!" << std::endl;
834 void GraphDisplayerCanvas::moveNode(double dx, double dy, Gnome::Canvas::Item * item, Node node)
836 Gnome::Canvas::Item * moved_item=item;
837 Node moved_node=node;
839 if(item==NULL && node==INVALID)
841 moved_item=active_item;
842 moved_node=active_node;
849 //repositioning node and its text
850 moved_item->move(dx, dy);
851 nodetextmap[moved_node]->move(dx, dy);
853 // the new coordinates of the centre of the node
854 double coord_x = dx + (mytab.mapstorage).coords[moved_node].x;
855 double coord_y = dy + (mytab.mapstorage).coords[moved_node].y;
857 // write back the new coordinates to the coords map
858 (mytab.mapstorage).coords.set(moved_node, XY(coord_x, coord_y));
860 //all the edges connected to the moved point has to be redrawn
861 for(OutEdgeIt ei((mytab.mapstorage).graph,moved_node);ei!=INVALID;++ei)
865 if (mytab.mapstorage.graph.source(ei) == mytab.mapstorage.graph.target(ei))
867 arrow_pos = mytab.mapstorage.arrow_pos[ei] + XY(dx, dy);
871 XY moved_node_1(coord_x - dx, coord_y - dy);
872 XY moved_node_2(coord_x, coord_y);
873 Node target = mytab.mapstorage.graph.target(ei);
874 XY fix_node(mytab.mapstorage.coords[target].x,
875 mytab.mapstorage.coords[target].y);
876 XY old_arrow_pos(mytab.mapstorage.arrow_pos[ei]);
878 arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton);
881 mytab.mapstorage.arrow_pos.set(ei, arrow_pos);
882 edgesmap[ei]->draw();
884 //reposition of edgetext
885 XY text_pos=mytab.mapstorage.arrow_pos[ei];
886 text_pos+=(XY(10,10));
887 edgetextmap[ei]->property_x().set_value(text_pos.x);
888 edgetextmap[ei]->property_y().set_value(text_pos.y);
891 for(InEdgeIt ei((mytab.mapstorage).graph,moved_node);ei!=INVALID;++ei)
893 if (mytab.mapstorage.graph.source(ei) != mytab.mapstorage.graph.target(ei))
895 XY moved_node_1(coord_x - dx, coord_y - dy);
896 XY moved_node_2(coord_x, coord_y);
897 Node source = mytab.mapstorage.graph.source(ei);
898 XY fix_node(mytab.mapstorage.coords[source].x,
899 mytab.mapstorage.coords[source].y);
900 XY old_arrow_pos(mytab.mapstorage.arrow_pos[ei]);
903 arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton);
905 mytab.mapstorage.arrow_pos.set(ei, arrow_pos);
906 edgesmap[ei]->draw();
908 //reposition of edgetext
909 XY text_pos=mytab.mapstorage.arrow_pos[ei];
910 text_pos+=(XY(10,10));
911 edgetextmap[ei]->property_x().set_value(text_pos.x);
912 edgetextmap[ei]->property_y().set_value(text_pos.y);
917 Gdk::Color GraphDisplayerCanvas::rainbowColorCounter(double min, double max, double w)
921 double pos=(w-min)/(max-min);
924 //rainbow transitions contain 6 phase
925 //in each phase only one color is changed
926 //first we determine the phase, in which
927 //the actual value belongs to
928 for (int i=0;i<=5;i++)
930 if(((double)i/6<pos)&&(pos<=(double(i+1)/6)))
937 //within its 1/6 long phase the relativ position
938 //determines the power of the color changed in
940 //we normalize that to one, to be able to give percentage
941 //value for the function
942 double rel_pos=(pos-(phase/6))*6;
947 color.set_rgb_p (1, 0, 1-rel_pos);
950 color.set_rgb_p (1, rel_pos, 0);
953 color.set_rgb_p (1-rel_pos, 1, 0);
956 color.set_rgb_p (0, 1, rel_pos);
959 color.set_rgb_p (0, 1-rel_pos, 1);
962 color.set_rgb_p ((rel_pos/3), 0, 1);
965 std::cout << "Wrong phase: " << phase << " " << pos << std::endl;
970 std::cout << "Wrong phase: " << phase << " " << pos << std::endl;