/****************************************************************** * * * Nest version 2 - 3D Wasp Nest Simulator * * Copyright (C) 1997 Sylvain GUERIN * * LIASC, ENST Bretagne & Santa Fe Institute * * * ****************************************************************** E-mail: Sylvain.Guerin@enst-bretagne.fr or: Sylvain Guerin 13 rue des Monts Lorgeaux, 51460 L'EPINE, FRANCE ****************************************************************** This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ****************************************************************** Name : ViewInt.c Component : view interface (architectures visualisation) Fonctionality : contains methods refering to the view interface ******************************************************************/ #include "ViewInt.h" #include "view3d.h" actionType ViewInterface::manageInterface (XEvent report) { actionType action; int i; char temp[256]; if (lightInterface) { /* si c'est juste l'inferface pour regarder la construction, on quitte tout de suite, en demandant quand meme la confirmation */ sprintf (temp, "Simulation complete (%ld cells built).", anArchitecture->cellsNumber); displayDialogBox (mainInterface, "Simulation", "Nest2", temp, "Continue"); /* avant de quitter, on va sauver tous les parametres de vue. comme ca, la prochaine fois, on les aura pareil */ anArchitecture->viewParameters.org = aView->get_org (); anArchitecture->viewParameters.zoom = aView->get_zoom (); anArchitecture->viewParameters.tx = aView->get_tx (); anArchitecture->viewParameters.ty = aView->get_ty (); anArchitecture->viewParameters.zCut = aView->getZCut (); anArchitecture->viewParameters.tetaCut = aView->getTetaCut (); anArchitecture->viewParameters.phiCut = aView->getPhiCut (); anArchitecture->viewParameters.isCut = isCut; anArchitecture->viewParameters.alpha = aView->get_alpha (); /* et puis maintenant, on en profite pour sauver la visualisation, tant qu'a faire */ aView->savePreview (); return endInterface; } if (report.type == ResizeRequest) { printf ("Resizing %d %d \n", report.xresizerequest.width, report.xresizerequest.height); width = report.xresizerequest.width; height = report.xresizerequest.height; deleteWindows (); resizeWindow (); createWindows (); aView->changeWindows (view3d->win, viewIcon->win); } if (exitButton->manageEvent (report) == buttonPressed) { if (anArchitecture != NULL) { /* avant de quitter, on va sauver tous les parametres de vue. comme ca, la prochaine fois, on les aura pareil */ anArchitecture->viewParameters.org = aView->get_org (); anArchitecture->viewParameters.zoom = aView->get_zoom (); anArchitecture->viewParameters.tx = aView->get_tx (); anArchitecture->viewParameters.ty = aView->get_ty (); anArchitecture->viewParameters.zCut = aView->getZCut (); anArchitecture->viewParameters.tetaCut = aView->getTetaCut (); anArchitecture->viewParameters.phiCut = aView->getPhiCut (); anArchitecture->viewParameters.isCut = isCut; anArchitecture->viewParameters.alpha = aView->get_alpha (); /* et puis maintenant, on en profite pour sauver la visualisation, tant qu'a faire */ aView->savePreview (); } return endInterface; } if (resizeButton->manageEvent (report) == buttonPressed) { aView->resize (); alreadyComputed = 0; displayView3d (); } if (cutButton->manageEvent (report) == buttonPressed) { alreadyComputed = 0; if (isCut == 0) { isCut = 1; } else { isCut = 0; } displayView3d (); } if (settingsButton->manageEvent (report) == buttonPressed) { manageSettings (); } translatePanel->manageEvent (report); if (viewIcon->manageEvent (report) == mustBeRefreshed) { aView->displayViewIcon (); }; if (leftButton->manageEvent (report) == buttonPressed) { aView->translate_view (LEFT); alreadyComputed = 0; displayView3d (); }; if (rightButton->manageEvent (report) == buttonPressed) { aView->translate_view (RIGHT); alreadyComputed = 0; displayView3d (); }; if (upButton->manageEvent (report) == buttonPressed) { aView->translate_view (UP); alreadyComputed = 0; displayView3d (); }; if (downButton->manageEvent (report) == buttonPressed) { aView->translate_view (DOWN); alreadyComputed = 0; displayView3d (); }; action = tetaUpButton->manageEvent (report); if ((action == buttonPressed) || (action == endOfPression)) { alreadyComputed = 0; for (i=0; ichange_teta (1); } aView->displayViewIcon (); changeTetaText (); // displayView3d (); /* a virer */ if ((action == endOfPression) || (continueRetracing == 1)) { displayView3d (); } }; action = tetaDownButton->manageEvent (report); if ((action == buttonPressed) || (action == endOfPression)) { alreadyComputed = 0; for (i=0; ichange_teta (0); } aView->displayViewIcon (); changeTetaText (); if ((action == endOfPression) || (continueRetracing == 1)) { displayView3d (); } }; tetaText->manageEvent (report); tetaTextLabel->manageEvent (report); action = phiUpButton->manageEvent (report); if ((action == buttonPressed) || (action == endOfPression)) { if (aView->get_phi () < M_PI/2) { alreadyComputed = 0; for (i=0; ichange_phi (1); } aView->displayViewIcon (); changePhiText (); } if ((action == endOfPression) || (continueRetracing == 1)) { displayView3d (); } }; action = phiDownButton->manageEvent (report); if ((action == buttonPressed) || (action == endOfPression)) { if (aView->get_phi () > -M_PI/2) { alreadyComputed = 0; for (i=0; ichange_phi (0); } aView->displayViewIcon (); changePhiText (); } if ((action == endOfPression) || (continueRetracing == 1)) { displayView3d (); } }; phiText->manageEvent (report); phiTextLabel->manageEvent (report); action = alphaUpButton->manageEvent (report); if ((action == buttonPressed) || (action == endOfPression)) { alreadyComputed = 0; for (i=0; ichange_alpha (1); } aView->displayViewIcon (); changeAlphaText (); if ((action == endOfPression) || (continueRetracing == 1)) { displayView3d (); } }; action = alphaDownButton->manageEvent (report); if ((action == buttonPressed) || (action == endOfPression)) { alreadyComputed = 0; for (i=0; ichange_alpha (0); } aView->displayViewIcon (); changeAlphaText (); if ((action == endOfPression) || (continueRetracing == 1)) { displayView3d (); } }; alphaText->manageEvent (report); alphaTextLabel->manageEvent (report); if (zoomUpButton->manageEvent (report) == buttonPressed) { alreadyComputed = 0; aView->change_zoom (0); aView->displayViewIcon (); changeZoomText (); displayView3d (); }; if (zoomDownButton->manageEvent (report) == buttonPressed) { alreadyComputed = 0; aView->change_zoom (1); aView->displayViewIcon (); changeZoomText (); displayView3d (); }; zoomText->manageEvent (report); zoomTextLabel->manageEvent (report); action = tetaCutUpButton->manageEvent (report); if (action == buttonPressed) { alreadyComputed = 0; aView->changeTetaCut (1); aView->displayViewIcon (); changeTetaCutText (); displayView3d (); }; action = tetaCutDownButton->manageEvent (report); if (action == buttonPressed) { alreadyComputed = 0; aView->changeTetaCut (0); aView->displayViewIcon (); changeTetaCutText (); displayView3d (); }; tetaCutText->manageEvent (report); tetaCutTextLabel->manageEvent (report); action = phiCutUpButton->manageEvent (report); if (action == buttonPressed) { alreadyComputed = 0; aView->changePhiCut (1); aView->displayViewIcon (); changePhiCutText (); displayView3d (); }; action = phiCutDownButton->manageEvent (report); if (action == buttonPressed) { alreadyComputed = 0; aView->changePhiCut (0); aView->displayViewIcon (); changePhiCutText (); displayView3d (); }; phiCutText->manageEvent (report); phiCutTextLabel->manageEvent (report); action = zCutUpButton->manageEvent (report); if (action == buttonPressed) { alreadyComputed = 0; aView->changeZCut (1); aView->displayViewIcon (); changeZCutText (); displayView3d (); }; action = zCutDownButton->manageEvent (report); if (action == buttonPressed) { alreadyComputed = 0; aView->changeZCut (0); aView->displayViewIcon (); changeZCutText (); displayView3d (); }; zCutText->manageEvent (report); zCutTextLabel->manageEvent (report); if (view3d->manageEvent (report) == mustBeRefreshed) { displayView3d (); } return noAction; } void ViewInterface::refresh () { if (!lightInterface) { exitButton->refresh (); resizeButton->refresh (); cutButton->refresh (); settingsButton->refresh (); translatePanel->refresh (); leftButton->refresh (); rightButton->refresh (); upButton->refresh (); downButton->refresh (); alphaUpButton->refresh (); alphaDownButton->refresh (); alphaText->refresh (); alphaTextLabel->refresh (); tetaUpButton->refresh (); tetaDownButton->refresh (); tetaText->refresh (); tetaTextLabel->refresh (); phiUpButton->refresh (); phiDownButton->refresh (); phiText->refresh (); phiTextLabel->refresh (); zoomUpButton->refresh (); zoomDownButton->refresh (); zoomText->refresh (); zoomTextLabel->refresh (); zCutUpButton->refresh (); zCutDownButton->refresh (); zCutText->refresh (); zCutTextLabel->refresh (); tetaCutUpButton->refresh (); tetaCutDownButton->refresh (); tetaCutText->refresh (); tetaCutTextLabel->refresh (); phiCutUpButton->refresh (); phiCutDownButton->refresh (); phiCutText->refresh (); phiCutTextLabel->refresh (); if (view3d->shouldBeRefreshed) displayView3d (); if (viewIcon->shouldBeRefreshed) aView->displayViewIcon (); } } ViewInterface::ViewInterface (Interface* theMainInterface, int x0, int y0, int aWidth, int aHeight, int constSize, char* windowLabel, char* iconLabel, Display* aDisplay, Architecture* anArch, SimulationType aSimuType, Window aPreviewWindow, int defaultSize) : Interface (x0, y0, aWidth, aHeight, constSize, windowLabel, iconLabel, aDisplay) { mainInterface = theMainInterface; anArchitecture = anArch; if (anArchitecture == NULL) lightInterface = 1; else lightInterface = 0; alreadyComputed = 0; createWindows (); if (anArchitecture != NULL) { aView = new View (display, view3d->win, *gc, viewIcon->win, color, displayMode, width-20, height-170, fontInfo, defaultDepth, anArchitecture, aSimuType, aPreviewWindow); aView->init_view (init_position (), /* on regarde le point origine */ anArchitecture->viewParameters.org, anArchitecture->viewParameters.zoom, 30, /* icon zoom */ 62, 62); /* tx, ty for icon */ aView->setViewCut (anArchitecture->viewParameters.zCut, anArchitecture->viewParameters.tetaCut, anArchitecture->viewParameters.phiCut); aView->set_alpha (anArchitecture->viewParameters.alpha); isCut = anArchitecture->viewParameters.isCut; aView->setTxTy (anArchitecture->viewParameters.tx, anArchitecture->viewParameters.ty); } else /* pas d'architecture initialisee, on met les parametres par defaut */ { aView = new View (display, view3d->win, *gc, viewIcon->win, color, displayMode, width-20, height-20, fontInfo, defaultDepth, anArchitecture, aSimuType, aPreviewWindow); anArchitecture = new Architecture(defaultSize, aSimuType); anArchitecture->setCell (0, 0, 0, RED, 0); anArchitecture->setCell (0, defaultSize-1, 0, RED, 0); anArchitecture->setCell (0, 0, defaultSize-1, RED, 0); anArchitecture->setCell (0, defaultSize-1, defaultSize-1, RED, 0); anArchitecture->setCell (defaultSize-1, 0, 0, RED, 0); anArchitecture->setCell (defaultSize-1, defaultSize-1, 0, RED, 0); anArchitecture->setCell (defaultSize-1, 0, defaultSize-1, RED, 0); anArchitecture->setCell (defaultSize-1, defaultSize-1, defaultSize-1, RED, 0); aView->setArchitecture (anArchitecture); /* on regarde le point origine */ aView->init_view (init_position (), anArchitecture->viewParameters.org, anArchitecture->viewParameters.zoom, 30, /* icon zoom */ 62, 62); /* tx, ty for icon */ aView->setViewCut (anArchitecture->viewParameters.zCut, anArchitecture->viewParameters.tetaCut, anArchitecture->viewParameters.phiCut); aView->set_alpha (anArchitecture->viewParameters.alpha); isCut = anArchitecture->viewParameters.isCut; aView->setTxTy (anArchitecture->viewParameters.tx, anArchitecture->viewParameters.ty); aView->resize (); delete anArchitecture; anArchitecture = NULL; aView->setArchitecture (NULL); } /* Maintenant, on met tous les textes a jour */ if (!lightInterface) { changeAlphaText (); changeTetaText (); changePhiText (); changeZoomText (); changeZCutText (); changeTetaCutText (); changePhiCutText (); } /* Initialisation des settings */ continueRetracingEnum.add ("No"); continueRetracingEnum.add ("Yes"); continueRetracingEnum.setDefault (defaultContinueRetracing); continueRetracing = defaultContinueRetracing; retracingSteps = defaultRetracingSteps; } void ViewInterface::createWindows () { if (lightInterface) { view3d = new GraphicWindow (this, 10, 10, width-20, height-20, enabled, ExposureMask, Black); viewIcon = new GraphicWindow (this, 0, 0, 5, 5, enabled, ExposureMask, Grey); } else { exitButton = new Button (this, 10, 10, 100, 25, "Close", centerJustified, enabled); resizeButton = new Button (this, 10, 40, 100, 25, "Resize", centerJustified, enabled); cutButton = new Button (this, 10, 70, 100, 25, "Cut", centerJustified, enabled); settingsButton = new Button (this, 10, 100, 100, 25, "Settings", centerJustified, enabled); viewIcon = new GraphicWindow (this, width-155, 15, 130, 130, enabled, ExposureMask, Black); view3d = new GraphicWindow (this, 10, 160, width-20, height-170, enabled, ExposureMask, Black); translatePanel = new RoundPanel (view3d, width-130, height-280, 100, 100); leftButton = new LeftArrow (translatePanel, 7, 38, enabled); rightButton = new RightArrow (translatePanel, 66, 38, enabled); upButton = new UpArrow (translatePanel, 37, 7, enabled); downButton = new DownArrow (translatePanel, 37, 66, enabled); tetaUpButton = new UpSquare (this, width-380, 20, enabled, continuePressing); tetaDownButton = new DownSquare (this, width-215, 20, enabled, continuePressing); tetaTextLabel = new TextWidget (this, width-335, 25, "teta = "); tetaText = new TextWidget (this, width-275, 25, "----"); phiUpButton = new UpSquare (this, width-380, 50, enabled, continuePressing); phiDownButton = new DownSquare (this, width-215, 50, enabled, continuePressing); phiTextLabel = new TextWidget (this, width-326, 55, "phi = "); phiText = new TextWidget (this, width-275, 55, "----"); alphaUpButton = new UpSquare (this, width-380, 80, enabled, continuePressing); alphaDownButton = new DownSquare (this, width-215, 80, enabled, continuePressing); alphaTextLabel = new TextWidget (this, width-344, 85, "alpha = "); alphaText = new TextWidget (this, width-275, 85, "----"); zoomUpButton = new UpSquare (this, width-380, 110, enabled); zoomDownButton = new DownSquare (this, width-215, 110, enabled); zoomTextLabel = new TextWidget (this, width-335, 115, "zoom = "); zoomText = new TextWidget (this, width-275, 115, "-----"); /* cuts */ int cutDecay = 210; zCutUpButton = new UpSquare (this, width-380-cutDecay, 20, enabled); zCutDownButton = new DownSquare (this, width-215-cutDecay, 20, enabled); zCutTextLabel = new TextWidget (this, width-335-cutDecay, 25, "zCut = "); zCutText = new TextWidget (this, width-275-cutDecay, 25, "-----"); tetaCutUpButton = new UpSquare (this, width-380-cutDecay, 50, enabled); tetaCutDownButton = new DownSquare (this, width-215-cutDecay, 50, enabled); tetaCutTextLabel = new TextWidget (this, width-344-cutDecay, 55, "teta0 = "); tetaCutText = new TextWidget (this, width-275-cutDecay, 55, "-----"); phiCutUpButton = new UpSquare (this, width-380-cutDecay, 80, enabled); phiCutDownButton = new DownSquare (this, width-215-cutDecay, 80, enabled); phiCutTextLabel = new TextWidget (this, width-335-cutDecay, 85, "phi0 = "); phiCutText = new TextWidget (this, width-275-cutDecay, 85, "-----"); } } void ViewInterface::deleteWindows () { /* please be careful to delete all graphic widgets in right order */ if (lightInterface) { delete view3d; delete viewIcon; } else { delete exitButton; delete resizeButton; delete cutButton; delete settingsButton; delete leftButton; delete rightButton; delete upButton; delete downButton; delete translatePanel; delete view3d; delete alphaUpButton; delete alphaDownButton; delete alphaText; delete alphaTextLabel; delete tetaUpButton; delete tetaDownButton; delete tetaText; delete tetaTextLabel; delete phiUpButton; delete phiDownButton; delete phiText; delete phiTextLabel; delete zoomUpButton; delete zoomDownButton; delete zoomText; delete zoomTextLabel; delete tetaCutUpButton; delete tetaCutDownButton; delete tetaCutText; delete tetaCutTextLabel; delete phiCutUpButton; delete phiCutDownButton; delete phiCutText; delete phiCutTextLabel; delete zCutUpButton; delete zCutDownButton; delete zCutText; delete zCutTextLabel; delete viewIcon; } } ViewInterface::~ViewInterface () { deleteWindows (); delete aView; } void ViewInterface::setArchitecture (Architecture* anArch) { anArchitecture = anArch; aView->setArchitecture (anArchitecture); } void ViewInterface::displayView3d () { if (anArchitecture != NULL) { /* pour les cas ou on affiche la construction en temps reel */ aView->drawNet (alreadyComputed, isCut); aView->displayTempScreen (); alreadyComputed = 1; XSync (display, False); /* xxx */ } } void ViewInterface::changeAlphaText () { char text[256]; if (aView->get_alpha() >= 0) sprintf (text, "+%.3d", (int)(aView->get_alpha()/M_PI*180)); else sprintf (text, "%.3d", (int)(aView->get_alpha()/M_PI*180)); alphaText->change(text); } void ViewInterface::changeTetaText () { char text[256]; if (aView->get_teta() >= 0) sprintf (text, "+%.3d", (int)(aView->get_teta()*180/M_PI)); else sprintf (text, "%.3d", (int)(aView->get_teta()*180/M_PI)); tetaText->change(text); } void ViewInterface::changePhiText () { char text[256]; if (aView->get_phi() >= 0) sprintf (text, "+%.3d", (int)(aView->get_phi()/M_PI*180)); else sprintf (text, "%.3d", (int)(aView->get_phi()/M_PI*180)); phiText->change(text); } void ViewInterface::changeZoomText () { char text[256]; if (aView->get_zoom() < 10) sprintf (text, "%4.3f", aView->get_zoom()); else if (aView->get_zoom() < 100) sprintf (text, "%4.2f", aView->get_zoom()); else if (aView->get_zoom() < 1000) sprintf (text, "%4.1f", aView->get_zoom()); else sprintf (text, "%.5f", aView->get_zoom()); zoomText->change(text); } void ViewInterface::changeTetaCutText () { char text[256]; double value; int roundedValue, beforeRounded; value = aView->getTetaCut()/M_PI*180; beforeRounded = (int)value; if ((value-beforeRounded) > 0.2) roundedValue = beforeRounded+1; else if ((value-beforeRounded) < -0.2) roundedValue = beforeRounded-1; else roundedValue = beforeRounded; if (aView->getTetaCut() >= 0) sprintf (text, "+%.3d", roundedValue); else sprintf (text, "%.3d", roundedValue); tetaCutText->change(text); } void ViewInterface::changePhiCutText () { char text[256]; double value; int roundedValue, beforeRounded; value = aView->getPhiCut()/M_PI*180; beforeRounded = (int)value; if ((value-beforeRounded) > 0.2) roundedValue = beforeRounded+1; else if ((value-beforeRounded) < -0.2) roundedValue = beforeRounded-1; else roundedValue = beforeRounded; if (aView->getPhiCut() >= 0) sprintf (text, "+%.3d", roundedValue); else sprintf (text, "%.3d", roundedValue); phiCutText->change(text); } void ViewInterface::changeZCutText () { char text[256]; if (aView->getZCut() >= 0) sprintf (text, "+%.3d", aView->getZCut()); else sprintf (text, "%.3d", aView->getZCut()); zCutText->change(text); } void ViewInterface::manageSettings () { int oldRetracingSteps; oldRetracingSteps = retracingSteps; displayInputBox (mainInterface, "Settings", "nest2", 2, 32); addIntInput (" Retracing steps ", 4, &retracingSteps); addEnumInput (" Continue Retracing ", 4, &continueRetracingEnum); if (manageInputBox ()) /* cancelled operation */ retracingSteps = oldRetracingSteps; else continueRetracing = continueRetracingEnum.defaultValue (); }