diff --git a/src/canvas.cpp b/src/canvas.cpp --- a/src/canvas.cpp +++ b/src/canvas.cpp @@ -19,8 +19,6 @@ * */ -#include - #include #include #include @@ -121,10 +119,10 @@ void FigureEditor::clear() } } - void FigureEditor::wheelEvent(QWheelEvent *event) - { - scaleView(pow((double)2, -event->delta() / 240.0)); - } +void FigureEditor::wheelEvent(QWheelEvent *event) +{ + scaleView(pow((double)2, -event->delta() / 240.0)); +} void FigureEditor::scaleView (qreal scaleFactor) @@ -134,20 +132,20 @@ void FigureEditor::scaleView (qreal scal scale (scaleFactor, scaleFactor); } -void FigureEditor::Save(const char *fname, const char *format, int sizex, int sizey) { - - QImage *image = new QImage(sizex, sizey, QImage::Format_RGB32); - image->fill(QColor(Qt::white).rgb()); - QPainter *painter=new QPainter(image); - - render(painter); - - image->save(QString(fname),format); - delete painter; - delete image; +void FigureEditor::Save(const char *fname, const char *format, int sizex, int sizey) +{ + + QImage *image = new QImage(sizex, sizey, QImage::Format_RGB32); + image->fill(QColor(Qt::white).rgb()); + QPainter *painter=new QPainter(image); + + render(painter); + + image->save(QString(fname),format); + delete painter; + delete image; } -//void FigureEditor::contentsMousePressEvent(QMouseEvent* e) void FigureEditor::mousePressEvent(QMouseEvent* e) { static QList selected; @@ -161,7 +159,7 @@ void FigureEditor::mousePressEvent(QMous qDebug() << "Magnification: " << Cell::Magnification() << endl; qDebug() << "Offsets: " << Cell::Offset() << endl; #endif - + QList l=scene()->items(p); @@ -170,47 +168,46 @@ void FigureEditor::mousePressEvent(QMous qDebug() << "Mouse button modifier: " << e->modifiers() << endl; #endif - if (e->button()==Qt::RightButton || l.size()==0) { - - //cerr << "Drawing an intersection line from " << p.x() << ", " << p.y() << endl; - intersection_line = new QGraphicsLineItem( 0, scene() ); - intersection_line->setPen( QPen( QColor("red"), 3, Qt::DashLine ) ); - intersection_line->setLine( QLineF(p,p) ); - intersection_line->setZValue( 100 ); - intersection_line->show(); - } - - for (QList::Iterator it=l.begin(); it!=l.end(); ++it) { - #ifdef QDEBUG - qDebug() << typeid(**it).name() << endl; - #endif + if (e->button()==Qt::RightButton || l.size()==0) { + + //cerr << "Drawing an intersection line from " << p.x() << ", " << p.y() << endl; + intersection_line = new QGraphicsLineItem( 0, scene() ); + intersection_line->setPen( QPen( QColor("red"), 3, Qt::DashLine ) ); + intersection_line->setLine( QLineF(p,p) ); + intersection_line->setZValue( 100 ); + intersection_line->show(); + } + + for (QList::Iterator it=l.begin(); it!=l.end(); ++it) { +#ifdef QDEBUG + qDebug() << typeid(**it).name() << endl; +#endif + + if ( !strcmp(typeid(**it).name(),"8NodeItem")) { - if ( !strcmp(typeid(**it).name(),"8NodeItem")) { - - stringstream data_strstream; - data_strstream << (dynamic_cast(*it))->getNode(); - dynamic_cast
(parent())->UserMessage(QString(data_strstream.str().c_str())); - - (dynamic_cast(*it))->OnClick(e->button()); + stringstream data_strstream; + data_strstream << (dynamic_cast(*it))->getNode(); + dynamic_cast
(parent())->UserMessage(QString(data_strstream.str().c_str())); + + (dynamic_cast(*it))->OnClick(e->button()); + } + else + if ( !strcmp(typeid(**it).name(),"8CellItem") ) { + + Cell &c=((dynamic_cast(*it))->getCell()); + // OnClick to be defined in end-user code + c.OnClick(e); + } else { + if ( !strcmp(typeid(**it).name(),"8WallItem") ) { + (dynamic_cast(*it))->OnClick(e); + } } - else - if ( !strcmp(typeid(**it).name(),"8CellItem") ) { - - Cell &c=((dynamic_cast(*it))->getCell()); - // OnClick to be defined in end-user code - c.OnClick(e); - } else { - if ( !strcmp(typeid(**it).name(),"8WallItem") ) { - (dynamic_cast(*it))->OnClick(e); - } - } - } + } FullRedraw(); moving = 0; } - -//void FigureEditor::contentsMouseMoveEvent(QMouseEvent* e) + void FigureEditor::mouseMoveEvent(QMouseEvent* e) { @@ -224,19 +221,19 @@ void FigureEditor::mouseMoveEvent(QMouse // get object's center of mass QPointF rotation_midpoint = mesh.Centroid()*Cell::Factor() - Cell::Offset(); - - + + // calculate rotation angle double dy = (rotation_midpoint.y() - p.y()); double dx = (rotation_midpoint.x() - p.x()); double new_rot_angle = atan2(dx, dy); double d_alpha = new_rot_angle - rot_angle; rot_angle = new_rot_angle; - + mesh.Rotate(d_alpha, ( Vector(rotation_midpoint) + Cell::Offset() ) / Cell::Factor() ); - + dynamic_cast
(parent())->Plot(0); - FullRedraw(); + FullRedraw(); return; } if ( moving ) { @@ -246,36 +243,36 @@ void FigureEditor::mouseMoveEvent(QMouse p.y() - moving_start.y()); moving_start = p; scene()->update(); - + } - + //cerr << "event"; - + // keep track of intersection line to interactively cut a growing leaf - + if ( intersection_line ) { - + QPointF sp = intersection_line -> line().p1(); // startpoint QPointF ep = mapToScene(e->pos()); // endpoint intersection_line -> setLine( QLineF(sp, ep) ); scene()->update(); // Need this for Mac FullRedraw(); - } + } } //void FigureEditor::contentsMouseReleaseEvent(QMouseEvent* e) void FigureEditor::mouseReleaseEvent(QMouseEvent* e) { - + emit MouseReleased(); // intersection line for leaf was finished now. - + if (e->button()==Qt::LeftButton) { if (intersection_line ) { - #ifdef QDEBUG +#ifdef QDEBUG qDebug() << "Trying to cut leaf" << endl; - #endif +#endif QPointF sp = intersection_line -> line().p1(); // startpoint QPointF ep = mapToScene(e->pos()); @@ -283,55 +280,55 @@ void FigureEditor::mouseReleaseEvent(QMo intersection_line -> show(); vector intersected_cells = getIntersectedCells(); - + // no cells selected, do nothing if (intersected_cells.size()==0) { - #ifdef QDEBUG +#ifdef QDEBUG qDebug() << "No cells detected :-(" << endl; - #endif +#endif return; } - - + + Vector startpoint = Vector(sp.x(), sp.y()) / Cell::Factor() - Cell::Offset(); Vector endpoint = Vector(ep.x(), ep.y()) / Cell::Factor() - Cell::Offset(); - + NodeSet *node_set = new NodeSet; - + for (vector::iterator it = intersected_cells.begin(); it != intersected_cells.end(); it++) { - + (*it)->setBrush(QBrush("purple")); - + Cell &c=(*it)->getCell(); - + // sometimes the cell hasn't properly divided yet before the // next division is called? so check for it? let's find a way // to do this later. Note that this functionality currently // might result in a segmentation fault for users who are // quickly dragging and releasing division lines... scene()->update(); - - #ifdef QDEBUG + +#ifdef QDEBUG qDebug() << "Dividing Cell " << c.Index() << endl; - #endif +#endif c.DivideOverGivenLine( startpoint, endpoint, true, node_set); } - + node_set->CleanUp(); mesh.AddNodeSet(node_set); - - #ifdef QDEBUG + +#ifdef QDEBUG qDebug() << "Done DivideOverGivenLine" << endl; - #endif +#endif mesh.TestIllegalWalls(); // Do the actual cutting and removing if (intersected_cells.size()) { mesh.CutAwayBelowLine( startpoint, endpoint ); - + // Correct flags of nodeset for ( NodeSet::iterator i = node_set->begin(); @@ -355,36 +352,36 @@ void FigureEditor::mouseReleaseEvent(QMo - #ifdef QDEBUG +#ifdef QDEBUG qDebug() << "Done CutAwayBelowLine" << endl; - #endif +#endif mesh.TestIllegalWalls(); mesh.RepairBoundaryPolygon(); - #ifdef QDEBUG +#ifdef QDEBUG qDebug() << "Done RepairBoundaryPolygon" << endl; - #endif +#endif mesh.TestIllegalWalls(); mesh.CleanUpWalls(); - #ifdef QDEBUG +#ifdef QDEBUG qDebug() << "Done CleanUpWalls" << endl; - #endif +#endif mesh.TestIllegalWalls(); } - + dynamic_cast
(parent())->Plot(); - - #ifdef QDEBUG - qDebug() << "NodeSet of cutting line: " << *node_set << endl; - #endif + +#ifdef QDEBUG + qDebug() << "NodeSet of cutting line: " << *node_set << endl; +#endif } } else if (e->button()==Qt::RightButton) { - + if (intersection_line /* && !angle_line*/) { - + QPointF p = mapToScene(e->pos()); QPointF sp = intersection_line->line().p1(); - + viewport()->setMouseTracking( TRUE ); } } @@ -392,37 +389,37 @@ void FigureEditor::mouseReleaseEvent(QMo // returns a vector of pointer to cells colliding with intersection line -vector FigureEditor::getIntersectedCells(void) { - +vector FigureEditor::getIntersectedCells(void) +{ vector colliding_cells; - + QList l = intersection_line->collidingItems( ); - - #ifdef QDEBUG + +#ifdef QDEBUG qDebug() << "l.size() = " << l.size() << endl; - #endif +#endif for (QList::Iterator it=l.begin(); it!=l.end(); ++it) { - - #ifdef QDEBUG + +#ifdef QDEBUG qDebug() << typeid(**it).name() << endl; - #endif - +#endif + if ( !strcmp(typeid(**it).name(),"8CellItem") ) { colliding_cells.push_back(dynamic_cast(*it)); } } - + delete intersection_line; intersection_line = 0; return colliding_cells; - } -void FigureEditor::FullRedraw(void) { - QList rl; - rl << sceneRect(); - updateScene(rl); +void FigureEditor::FullRedraw(void) +{ + QList rl; + rl << sceneRect(); + updateScene(rl); } @@ -465,53 +462,53 @@ Main::Main(QGraphicsScene& c, Mesh &m, Q { editor = new FigureEditor(canvas,mesh, this); - #ifdef QDEBUG +#ifdef QDEBUG qDebug() << "Interactive = " << editor->isEnabled(); - #endif +#endif working_dir = 0; QObject::connect( editor, SIGNAL(MousePressed()), this, SLOT(PauseIfRunning())); QObject::connect( editor, SIGNAL(MouseReleased()), this, SLOT(ContIfRunning())); QMenuBar* menu = menuBar(); - + Q3PopupMenu* file = new Q3PopupMenu( menu ); - file->insertItem("&Read leaf", this, SLOT(readStateXML())); - file->insertItem("&Save leaf", this, SLOT(saveStateXML())); - file->insertItem("Snapshot", this, SLOT(snapshot()), Qt::CTRL+Qt::SHIFT+Qt::Key_S); + file->insertItem("&Read leaf", this, SLOT(readStateXML())); + file->insertItem("&Save leaf", this, SLOT(saveStateXML())); + file->insertItem("Snapshot", this, SLOT(snapshot()), Qt::CTRL+Qt::SHIFT+Qt::Key_S); + + file->insertSeparator(); + file->insertItem("Read next leaf", this, SLOT(readNextStateXML()), Qt::Key_PageDown); + file->insertItem("Read previous leaf", this, SLOT(readPrevStateXML()), Qt::Key_PageUp); + file->insertItem("Read last leaf", this, SLOT(readLastStateXML()), Qt::Key_End); + file->insertItem("Read first leaf", this, SLOT(readFirstStateXML()), Qt::Key_Home); - file->insertSeparator(); - file->insertItem("Read next leaf", this, SLOT(readNextStateXML()), Qt::Key_PageDown); - file->insertItem("Read previous leaf", this, SLOT(readPrevStateXML()), Qt::Key_PageUp); - file->insertItem("Read last leaf", this, SLOT(readLastStateXML()), Qt::Key_End); - file->insertItem("Read first leaf", this, SLOT(readFirstStateXML()), Qt::Key_Home); - - file->insertSeparator(); - file->insertItem("&Print...", this, SLOT(print()), Qt::CTRL+Qt::Key_P); - file->insertSeparator(); - file->insertItem("E&xit", qApp, SLOT(quit()), Qt::CTRL+Qt::Key_Q); - menu->insertItem("&File", file); - - Q3PopupMenu* edit = new Q3PopupMenu( menu ); + file->insertSeparator(); + file->insertItem("&Print...", this, SLOT(print()), Qt::CTRL+Qt::Key_P); + file->insertSeparator(); + file->insertItem("E&xit", qApp, SLOT(quit()), Qt::CTRL+Qt::Key_Q); + menu->insertItem("&File", file); + + Q3PopupMenu* edit = new Q3PopupMenu( menu ); edit->insertItem("Reset Chemicals and Transporters", this, SLOT( CleanMesh()), Qt::CTRL+Qt::Key_R ); - edit->insertItem("Reset Chemicals", this, SLOT( CleanMeshChemicals()) ); - edit->insertItem("Reset Transporters", this, SLOT( CleanMeshTransporters()) ); + edit->insertItem("Reset Chemicals", this, SLOT( CleanMeshChemicals()) ); + edit->insertItem("Reset Transporters", this, SLOT( CleanMeshTransporters()) ); edit->insertItem("Randomize PIN1 Transporters", this, SLOT( RandomizeMesh()) ); edit->insertItem("Cut away SAM", this, SLOT( CutSAM() )); menu->insertItem("&Edit", edit); run = new Q3PopupMenu( menu ); running = false; - paused_id = run->insertItem("&Simulation paused", this, SLOT(togglePaused()), Qt::Key_S); + paused_id = run->insertItem("&Simulation paused", this, SLOT(togglePaused()), Qt::Key_S); run->setItemChecked(paused_id, FALSE); menu->insertItem("&Run", run); - + view = new Q3PopupMenu( menu ); - view->insertItem("&Zoom in", this, SLOT(zoomIn()), Qt::CTRL+Qt::Key_Equal); + view->insertItem("&Zoom in", this, SLOT(zoomIn()), Qt::CTRL+Qt::Key_Equal); view->insertItem("Zoom &out", this, SLOT(zoomOut()), Qt::CTRL+Qt::Key_Minus); - view->insertSeparator(); - com_id = view->insertItem("Show cell ¢ers", this, SLOT(toggleShowCellCenters())); + view->insertSeparator(); + com_id = view->insertItem("Show cell ¢ers", this, SLOT(toggleShowCellCenters())); view->setItemChecked(com_id, FALSE); mesh_id = view->insertItem("Show &nodes", this, SLOT(toggleShowNodes()), Qt::CTRL+Qt::SHIFT+Qt::Key_N); @@ -530,37 +527,37 @@ Main::Main(QGraphicsScene& c, Mesh &m, Q fluxes_id = view->insertItem("Show &fluxes", this, SLOT(toggleShowFluxes())); view->setItemChecked(fluxes_id, FALSE); cell_walls_id = view->insertItem("Show transporters", this, SLOT(toggleShowWalls())); - view->setItemChecked(cell_walls_id, FALSE); - apoplasts_id = view->insertItem("Show apoplasts", this, SLOT(toggleShowApoplasts())); + view->setItemChecked(cell_walls_id, FALSE); + apoplasts_id = view->insertItem("Show apoplasts", this, SLOT(toggleShowApoplasts())); view->setItemChecked(apoplasts_id, FALSE); - view->insertSeparator(); - only_boundary_id = view->insertItem("Show only leaf &boundary", this, SLOT(toggleLeafBoundary())); - view->insertSeparator(); - movie_frames_id = view->insertItem("Start saving movie &frames", this, SLOT(toggleMovieFrames())); + view->insertSeparator(); + only_boundary_id = view->insertItem("Show only leaf &boundary", this, SLOT(toggleLeafBoundary())); + view->insertSeparator(); + movie_frames_id = view->insertItem("Start saving movie &frames", this, SLOT(toggleMovieFrames())); view->setItemChecked(movie_frames_id, par.movie); - - view->setItemChecked(only_boundary_id, FALSE); + + view->setItemChecked(only_boundary_id, FALSE); menu->insertItem("&View", view); - - + + options = new Q3PopupMenu( menu ); dyn_cells_id = options->insertItem("Cell growth", this, SLOT(toggleDynCells())); options->setItemChecked(dyn_cells_id, true); options->insertItem("Edit ¶meters", this, SLOT(EditParameters()), Qt::CTRL+Qt::Key_E); - + rotation_mode_id = options->insertItem("Rotate leaf", this, SLOT(EnterRotationMode()), Qt::CTRL + Qt::SHIFT + Qt::Key_R); options->setItemChecked(rotation_mode_id, false); menu->insertItem("&Options",options); - - // Menu of models - modelmenu = new QMenu( menu ); - menu->insertItem("&Models", modelmenu); - - + + // Menu of models + modelmenu = new QMenu( menu ); + menu->insertItem("&Models", modelmenu); + + menu->insertSeparator(); - + helpmenu = new Q3PopupMenu( menu ); tooltips_id = helpmenu->insertItem("Show Cell&Info", this, SLOT(Refresh())); helpmenu->setItemChecked(tooltips_id, true); @@ -572,44 +569,41 @@ Main::Main(QGraphicsScene& c, Mesh &m, Q setCentralWidget(editor); printer = 0; init(); - + // Start timer which repetitively invokes // a simulation time step timer = new QTimer( this ); connect( timer, SIGNAL(timeout()), SLOT(TimeStepWrap()) ); - + stopSimulation(); statusBar()->addWidget(new QLabel("Ready.")); setCaption(caption); gifanim = 0; - - infobar = new InfoBar(); - addDockWindow(infobar); + infobar = new InfoBar(); + addDockWindow(infobar); } -void Main::RefreshInfoBar(void) { - infobar->SetText(mesh.ModelID()); +void Main::RefreshInfoBar(void) +{ + infobar->SetText(mesh.ModelID()); } -void Main::UserMessage(QString message, int timeout) { - +void Main::UserMessage(QString message, int timeout) +{ statusBar()->showMessage(message, timeout); - } void Main::init() { clear(); - + static int r=24; srand(++r); - + mainCount++; - - } Main::~Main() @@ -630,21 +624,22 @@ void Main::newView() } -void Main::EditParameters() { - +void Main::EditParameters() +{ + ParameterDialog *pardial = new ParameterDialog(this, "stridediag"); // Make sure the values in the parameter dialog are updated after a file is read // each method changing the parameters (reading XML or PAR files) should // emit this signal QObject::connect( this, SIGNAL( ParsChanged() ), pardial, SLOT( Reset() ) ); - } -void Main::savePars() { - +void Main::savePars() +{ + stopSimulation(); - + Q3FileDialog *fd = new Q3FileDialog( this, "file dialog", TRUE ); fd->setMode( Q3FileDialog::AnyFile ); fd->setFilter( "Parameter files (*.par)"); @@ -657,13 +652,13 @@ void Main::savePars() { } startSimulation(); - } -void Main::readPars() { - +void Main::readPars() +{ + stopSimulation(); - + Q3FileDialog *fd = new Q3FileDialog( this, "file dialog", TRUE ); fd->setMode( Q3FileDialog::ExistingFile ); fd->setFilter( "Parameter files (*.par)"); @@ -673,22 +668,22 @@ void Main::readPars() { fileName = fd->selectedFile(); par.Read((const char *)fileName); } - + emit ParsChanged(); /* if (timer_active) timer->start( 0 );*/ - } -void Main::saveStateXML() { - +void Main::saveStateXML() +{ + stopSimulation(); Q3FileDialog *fd = new Q3FileDialog( this, "file dialog", TRUE ); fd->setMode( Q3FileDialog::AnyFile ); fd->setFilter( "XML (*.xml)"); QString fileName; - + if ( fd->exec() == QDialog::Accepted ) { fileName = fd->selectedFile(); if ( QFile::exists( fileName ) && @@ -701,27 +696,27 @@ void Main::saveStateXML() { tr("&Yes"), tr("&No"), QString::null, 1, 1 ) ) { return saveStateXML(); - + } else { - + mesh.XMLSave((const char *)fileName, XMLSettingsTree()); - + } } - } -void Main::snapshot() { - - +void Main::snapshot() +{ + + stopSimulation(); Q3FileDialog *fd = new Q3FileDialog( this, "Save snapshot", TRUE ); fd->setMode( Q3FileDialog::AnyFile ); - + QString fileName; - + if ( fd->exec() == QDialog::Accepted ) { fileName = fd->selectedFile(); if ( QFile::exists( fileName ) && @@ -734,37 +729,37 @@ void Main::snapshot() { tr("&Yes"), tr("&No"), QString::null, 1, 1 ) ) { return snapshot(); - + } else { - + // extract extension from filename - QString extension = getExtension(fileName); - - // Save bitmaps at 1024x768 - Save((const char *)fileName, extension, 1024, 768); + QString extension = getExtension(fileName); + + // Save bitmaps at 1024x768 + Save((const char *)fileName, extension, 1024, 768); } } - } - + -void Main::readPrevStateXML() { - +void Main::readPrevStateXML() +{ + // if we have already read a file, read the next file if (!currentFile.isEmpty() && working_dir) { QString next_file; - + QStringList xml_files = working_dir->entryList("*.xml"); QString currentFile_nopath = currentFile.section( '/', -1 ); QString currentFile_path = currentFile.section( '/', 0, -2 ); - + QList::iterator f = xml_files.find( currentFile_nopath ); - + if (f == xml_files.end()) { return; } - + if (f==xml_files.begin()) { QMessageBox mb( "Read previous leaf", "No more files", @@ -777,38 +772,39 @@ void Main::readPrevStateXML() { } next_file = *(--f); next_file = currentFile_path+"/"+next_file; - + readStateXML((const char *)next_file); - + } } -int Main::readStateXML(const char *filename, bool geometry, bool pars, bool simtime) { - +int Main::readStateXML(const char *filename, bool geometry, bool pars, bool simtime) +{ + try { xmlNode *settings; mesh.XMLRead((const char *)filename, &settings, geometry, pars, simtime); - #ifdef QDEBUG +#ifdef QDEBUG qDebug() << "Reading done."<< endl; - #endif +#endif XMLReadSettings(settings); xmlFree(settings); Cell::SetMagnification(1); Cell::setOffset(0,0); - + FitLeafToCanvas(); - + currentFile = QString(filename); - + Plot(); QString status_message = QString("Successfully read leaf from file %1. Time is %2 h.").arg(currentFile).arg(mesh.getTimeHours().c_str()); cerr << status_message.toStdString() << endl; - setCaption(caption_with_file.arg(filename)); + setCaption(caption_with_file.arg(filename)); statusBar()->message(status_message); emit ParsChanged(); - #ifdef QDEBUG +#ifdef QDEBUG qDebug() << "Done. Returning 0." << endl; - #endif +#endif return 0; } catch (const char *error_message) { QMessageBox mb( "Read leaf from XML file", @@ -820,27 +816,27 @@ int Main::readStateXML(const char *filen mb.exec(); return 1; } - } -void Main::readNextStateXML() { - +void Main::readNextStateXML() +{ + // if we have already read a file, read the next file if (!currentFile.isEmpty() && working_dir) { QString next_file; - + QStringList xml_files = working_dir->entryList("*.xml"); QString currentFile_nopath = currentFile.section( '/', -1 ); QString currentFile_path = currentFile.section( '/', 0, -2 ); - - + + QList::iterator f = xml_files.find( currentFile_nopath ); - + if (f == xml_files.end()) { return; } - + ++f; if (f==xml_files.end()) { QMessageBox mb( "Read next leaf", @@ -857,61 +853,58 @@ void Main::readNextStateXML() { readStateXML((const char*)next_file); } - - } -void Main::readLastStateXML() { - +void Main::readLastStateXML() +{ + // if we have already read a file, read the next file if (!currentFile.isEmpty() && working_dir) { QString next_file; - + QStringList xml_files = working_dir->entryList("*.xml"); QString currentFile_nopath = currentFile.section( '/', -1 ); QString currentFile_path = currentFile.section( '/', 0, -2 ); - - + + next_file = xml_files.back(); - + next_file = currentFile_path+"/"+next_file; readStateXML((const char*)next_file); } - - } -void Main::readFirstStateXML() { - +void Main::readFirstStateXML() +{ + // if we have already read a file, read the next file if (!currentFile.isEmpty() && working_dir) { QString next_file; - + QStringList xml_files = working_dir->entryList("*.xml"); QString currentFile_nopath = currentFile.section( '/', -1 ); QString currentFile_path = currentFile.section( '/', 0, -2 ); - - + + next_file = xml_files.front(); - + next_file = currentFile_path+"/"+next_file; readStateXML((const char*)next_file); } - - } -void Main::readStateXML() { +void Main::readStateXML() +{ // extern Mesh mesh; stopSimulation(); - #ifdef QDEBUG +#ifdef QDEBUG qDebug() << "Trying to open an OptionFileDialog" << endl; - #endif +#endif OptionFileDialog *fd = new OptionFileDialog( this, "read dialog", TRUE ); fd->setMode( OptionFileDialog::ExistingFile ); fd->setFilter( "XML files (*.xml)"); @@ -920,13 +913,13 @@ void Main::readStateXML() { } QString fileName; if ( fd->exec() == QDialog::Accepted ) { - + fileName = fd->selectedFile(); if (working_dir) { delete working_dir; } working_dir = fd->dir(); - + if (readStateXML((const char *)fileName,fd->readGeometryP(), fd->readParametersP()) ) return readStateXML(); // user can try again } @@ -947,7 +940,7 @@ void Main::help() "Leaf growth computer model
" "(c) 2005-2007, Roeland Merks
" "VIB Department Plant Systems Biology
" - "Ghent, Belgium
" + "Ghent, Belgium
" "(c) 2008-2009, Roeland Merks
" "CWI/NCSB, Amsterdam, Netherlands
" "Pilot release for WUR/Biometris, 21-10-2009
", @@ -956,294 +949,315 @@ void Main::help() about->show(); } - void Main::aboutQt() - { - QMessageBox::aboutQt( this, "Virtual Leaf" ); - } +void Main::aboutQt(){ + QMessageBox::aboutQt( this, "Virtual Leaf" ); +} - void Main::toggleShowCellCenters() - { - Plot(); - } +void Main::toggleShowCellCenters() +{ + Plot(); +} - void Main::toggleShowWalls() - { - Plot(); - } +void Main::toggleShowWalls() +{ + Plot(); +} + void Main::toggleShowApoplasts() { - Plot(); + Plot(); } - void Main::toggleShowNodes() - { - Plot(); - } + +void Main::toggleShowNodes() +{ + Plot(); +} - void Main::toggleNodeNumbers(void) { - Plot(); - } +void Main::toggleNodeNumbers(void) +{ + Plot(); +} - void Main::toggleCellNumbers(void) { - Plot(); - } +void Main::toggleCellNumbers(void) +{ + Plot(); +} - void Main::toggleCellAxes(void) { - Plot(); - } - - void Main::toggleCellStrain(void) { - Plot(); - } +void Main::toggleCellAxes(void) +{ + Plot(); +} - void Main::toggleShowFluxes(void) { - Plot(); - } +void Main::toggleCellStrain(void) +{ + Plot(); +} - void Main::toggleShowBorderCells(){ - Plot(); - } +void Main::toggleShowFluxes(void) +{ + Plot(); +} -void Main::toggleHideCells(void) { - Plot(); - editor->FullRedraw(); +void Main::toggleShowBorderCells() +{ + Plot(); } - void Main::toggleMovieFrames(){} - void Main::toggleLeafBoundary(){} +void Main::toggleHideCells(void) +{ + Plot(); + editor->FullRedraw(); +} + +void Main::toggleMovieFrames(){} + +void Main::toggleLeafBoundary(){} + +void Main::toggleDynCells() {} - void Main::toggleDynCells() {} - - void Main::startSimulation(void) { - timer->start( 0 ); - statusBar()->message("Simulation started"); - running = true; - } +void Main::startSimulation(void) +{ + timer->start( 0 ); + statusBar()->message("Simulation started"); + running = true; +} - void Main::stopSimulation(void) { - timer->stop(); - cerr << "Stopping simulation" << endl; - statusBar()->message("Simulation paused"); - running = false; +void Main::stopSimulation(void) +{ + timer->stop(); + cerr << "Stopping simulation" << endl; + statusBar()->message("Simulation paused"); + running = false; +} + +void Main::togglePaused() +{ + bool s = run->isItemChecked(paused_id); + if (s) { + cerr << "Calling start simulation" << endl; + startSimulation(); + } else { + cerr << "Calling stop simulation" << endl; + stopSimulation(); } +} - void Main::togglePaused() - { - bool s = run->isItemChecked(paused_id); - if (s) { - cerr << "Calling start simulation" << endl; - startSimulation(); - } else { - cerr << "Calling stop simulation" << endl; - stopSimulation(); - } - } - - void Main::setFluxArrowSize(int size) { - - flux_arrow_size = size/100.; - } +void Main::setFluxArrowSize(int size) +{ + flux_arrow_size = size/100.; +} - void Main::enlarge() - { - canvas.setSceneRect( QRectF( 0,0, canvas.width()*4./3., canvas.height()*4./3.) ); - } +void Main::enlarge() +{ + canvas.setSceneRect( QRectF( 0,0, canvas.width()*4./3., canvas.height()*4./3.) ); +} - void Main::shrink() - { - canvas.setSceneRect( QRectF( 0,0, canvas.width()*3/4, canvas.height()*3/4) ); - } +void Main::shrink() +{ + canvas.setSceneRect( QRectF( 0,0, canvas.width()*3/4, canvas.height()*3/4) ); +} - void Main::scale(double factor) { - QMatrix m = editor->matrix(); - m.scale(factor, factor); - editor->setMatrix( m ); - } +void Main::scale(double factor) +{ + QMatrix m = editor->matrix(); + m.scale(factor, factor); + editor->setMatrix( m ); +} - void Main::zoomIn() - { - QMatrix m = editor->matrix(); - m.scale( 1.1, 1.1 ); - editor->setMatrix( m ); - } +void Main::zoomIn() +{ + QMatrix m = editor->matrix(); + m.scale( 1.1, 1.1 ); + editor->setMatrix( m ); +} - void Main::zoomOut() - { - QMatrix m = editor->matrix(); - m.scale( 0.9, 0.9 ); - editor->setMatrix( m ); - } +void Main::zoomOut() +{ + QMatrix m = editor->matrix(); + m.scale( 0.9, 0.9 ); + editor->setMatrix( m ); +} - void Main::print() - { - if ( !printer ) printer = new QPrinter; - - if ( printer->setup(this) ) { - - // extern Mesh mesh; - Vector bbll,bbur; - mesh.BoundingBox(bbll,bbur); +void Main::print() +{ + if ( !printer ) printer = new QPrinter; + + if ( printer->setup(this) ) { + + // extern Mesh mesh; + Vector bbll,bbur; + mesh.BoundingBox(bbll,bbur); - #ifdef QDEBUG - qDebug() << "bbll = " << bbll << endl; - qDebug() << "bbur = " << bbur << endl; - #endif - double cw = (bbur.x - bbll.x); - double ch = (bbur.y - bbll.y); - QPainter pp(printer); - QRect vp=pp.viewport(); - #ifdef QDEBUG - qDebug() << "Paper width = " << vp.width() << " x " << vp.height() << endl; - #endif +#ifdef QDEBUG + qDebug() << "bbll = " << bbll << endl; + qDebug() << "bbur = " << bbur << endl; +#endif + double cw = (bbur.x - bbll.x); + double ch = (bbur.y - bbll.y); + QPainter pp(printer); + QRect vp=pp.viewport(); +#ifdef QDEBUG + qDebug() << "Paper width = " << vp.width() << " x " << vp.height() << endl; +#endif - // Note that Cell is also translated... - pp.translate(-bbur.x,-bbur.y); - if (cw>ch) { - pp.scale(vp.width()/(2*cw*Cell::Magnification()), vp.width()/(2*cw*Cell::Magnification())); - } else { - pp.scale(vp.height()/(2*ch*Cell::Magnification()), vp.height()/(2*ch*Cell::Magnification())); - } - canvas.render(&pp, QRectF(), QRectF(0.,0.,canvas.width(),canvas.height())); + // Note that Cell is also translated... + pp.translate(-bbur.x,-bbur.y); + if (cw>ch) { + pp.scale(vp.width()/(2*cw*Cell::Magnification()), vp.width()/(2*cw*Cell::Magnification())); + } else { + pp.scale(vp.height()/(2*ch*Cell::Magnification()), vp.height()/(2*ch*Cell::Magnification())); } + canvas.render(&pp, QRectF(), QRectF(0.,0.,canvas.width(),canvas.height())); } +} - void Main::TimeStepWrap(void) { - - static int t=0; - TimeStep(); - t++; - // check number of timesteps - if (t==par.nit) { - emit SimulationDone(); - } +void Main::TimeStepWrap(void) +{ + static int t=0; + TimeStep(); + t++; + // check number of timesteps + if (t==par.nit) { + emit SimulationDone(); } +} - void Main::RestartSim(void) { - - stopSimulation(); - if ( QMessageBox::question( - this, - tr("Restart simulation?"), - tr("Restart simulation.\n" - "Are you sure?"), - QMessageBox::Yes | QMessageBox::No, QMessageBox::NoButton ) == QMessageBox::Yes ) { +void Main::RestartSim(void) +{ - cerr << "Restarting simulation" << endl; - // extern Mesh mesh; - mesh.Clear(); - Init(); - Plot(); - editor->FullRedraw(); - } - //startSimulation(); - } + stopSimulation(); + if ( QMessageBox::question( + this, + tr("Restart simulation?"), + tr("Restart simulation.\n" + "Are you sure?"), + QMessageBox::Yes | QMessageBox::No, QMessageBox::NoButton ) == QMessageBox::Yes ) { + + cerr << "Restarting simulation" << endl; + // extern Mesh mesh; + mesh.Clear(); + Init(); + Plot(); + editor->FullRedraw(); + } + //startSimulation(); +} -void Main::FitCanvasToWindow(void) { - +void Main::FitCanvasToWindow(void) +{ + double scale_factor_x = (double)editor->width()/(double)canvas.width(); double scale_factor_y = (double)editor->height()/(double)canvas.height(); double scale_factor = scale_factor_x > scale_factor_y ? scale_factor_x : scale_factor_y; QMatrix m = editor->matrix(); - #ifdef QDEBUG +#ifdef QDEBUG qDebug() << "editor->width() = " << editor->width() << endl; qDebug() << "editor->height() = " << editor->height() << endl; - + qDebug() << "scale_factor = " << scale_factor << endl; qDebug() << "scale_factor_x = " << scale_factor_x << endl; qDebug() << "scale_factor_y = " << scale_factor_y << endl; - #endif +#endif m.scale( scale_factor, scale_factor ); editor->setMatrix( m ); editor->show(); } - void Main::PauseIfRunning(void) { - if (running) { - timer->stop(); - } +void Main::PauseIfRunning(void) +{ + if (running) { + timer->stop(); } +} - void Main::ContIfRunning(void) { - if (running) { - timer->start( 0 ); - } +void Main::ContIfRunning(void) +{ + if (running) { + timer->start( 0 ); } +} -void Main::FitLeafToCanvas(void) { +void Main::FitLeafToCanvas(void) +{ Vector ll,ur; mesh.BoundingBox(ll, ur); - + ll*=Cell::Magnification(); ur*=Cell::Magnification(); - + // give the leaf some space Vector border = ((ur-ll)/5.); - + QRectF bb( ll.x - border.x, ll.y - border.y, ur.x-ll.x + 2*border.x, ur.y-ll.y + 2*border.y ); - - + + // cerr << ur << ", " << ll << endl; editor->fitInView(bb, Qt::KeepAspectRatio); } -void Main::CleanMesh(void) { - vector clean_chem(Cell::NChem()); - vector clean_transporters(Cell::NChem()); +void Main::CleanMesh(void) +{ + vector clean_chem(Cell::NChem()); + vector clean_transporters(Cell::NChem()); - for (int i=0;iFullRedraw(); + for (int i=0;iFullRedraw(); } -void Main::CleanMeshChemicals(void) { - - vector clean_chem(Cell::NChem()); +void Main::CleanMeshChemicals(void) +{ + + vector clean_chem(Cell::NChem()); - for (int i=0;iFullRedraw(); + for (int i=0;iFullRedraw(); } -void Main::CleanMeshTransporters(void) { - vector clean_transporters(Cell::NChem()); - for (int i=0;iFullRedraw(); +void Main::CleanMeshTransporters(void) +{ + vector clean_transporters(Cell::NChem()); + for (int i=0;iFullRedraw(); } -void Main::RandomizeMesh(void) { - +void Main::RandomizeMesh(void) +{ + vector max_chem(Cell::NChem()); vector max_transporters(Cell::NChem()); - + for (int i=0;isetItemChecked(com_id, showcentersp); @@ -1274,10 +1289,11 @@ void Main::XMLReadSettings(xmlNode *sett view->setItemChecked(hide_cells_id, hidecellsp); options->setItemChecked(dyn_cells_id, dynamicscellsp); view->setItemChecked( cell_walls_id, showwallsp); - view->setItemChecked( apoplasts_id, showapoplastsp); + view->setItemChecked( apoplasts_id, showapoplastsp); } -xmlNode *Main::XMLSettingsTree(void) { +xmlNode *Main::XMLSettingsTree(void) +{ showcentersp = view->isItemChecked(com_id); showmeshp = view->isItemChecked(mesh_id); @@ -1291,11 +1307,10 @@ xmlNode *Main::XMLSettingsTree(void) { showfluxesp = view->isItemChecked(fluxes_id); dynamicscellsp = options->isItemChecked(dyn_cells_id); showwallsp = view->isItemChecked( cell_walls_id); - showapoplastsp = view->isItemChecked( apoplasts_id); + showapoplastsp = view->isItemChecked( apoplasts_id); hidecellsp = view->isItemChecked( hide_cells_id); return MainBase::XMLSettingsTree(); } /* finis */ -