/****************************************************************** * * * 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 : PatternInt.c Component : evaluation interface Fonctionality : contains methods refering to the pattern interface ******************************************************************/ #include "PatternInt.h" #include "config.h" PatternInterface::PatternInterface (Interface* theMainInterface, int x0, int y0, char* windowLabel, char* iconLabel, Display* aDisplay, Simulation* aSimulation) : Interface (x0, y0, 420, 340, 1, windowLabel, iconLabel, aDisplay) { position org, dest; mainInterface = theMainInterface; simulation = aSimulation; graph = simulation->simulationArchitecture->graph; currentPatternId = 0; currentPattern = new Architecture (simulation->archSize+1, simulation->simuType); closeButton = new Button (this, 10, 10, 110, 25, "Close", centerJustified, enabled); searchButton = new Button (this, 10, 40, 110, 25, "Search", centerJustified, enabled); coherenceButton = new Button (this, 10, 70, 110, 25, "Coherence", centerJustified, enabled); bar1 = new HorizontalBar (this, 130, 10, 280); bar2 = new HorizontalBar (this, 130, 40, 280); patternText = new TextWidget (this, 200, 20, "Pattern --- of ---"); incButton = new UpArrow (this, 35, 305, enabled); decButton = new DownArrow (this, 65, 305, enabled); patternWindow = new GraphicWindow (this, 130, 50, 280, 280, enabled, ExposureMask, Black); viewIcon = new GraphicWindow (this, 0, 0, 5, 5, disabled, ExposureMask, Grey); /* cette window est "bidon": elle sert pour l'affichage 3d */ view3d = new View (display, patternWindow->win, *gc, viewIcon->win, color, displayMode, 280, 280, fontInfo, defaultDepth, currentPattern, simulation->simuType, this->win); org = init_position (); org.x = 5; org.y = -2; org.z = 3.5; dest = init_position (); view3d->init_view (dest, org, 50, 20, 50, 50); view3d->set_alpha (M_PI); view3d->unsetAxes (); updatePatternText (); } PatternInterface::~PatternInterface () { delete view3d; delete currentPattern; delete closeButton; delete searchButton; delete coherenceButton; delete bar1; delete bar2; delete patternText; delete incButton; delete decButton; delete patternWindow; delete viewIcon; } actionType PatternInterface::manageInterface (XEvent report) { /* USELESS actionType action; */ /* USELESS int i; */ char temp[256]; if (closeButton->manageEvent (report) == buttonPressed) { /* avant de quitter, on vire tous les patterns */ graph->freeAllPatterns (); return endInterface; } if (searchButton->manageEvent (report) == buttonPressed) { displayAbortableInfoBox (mainInterface, "Search patterns", "Nest2", "Patterns searching is running, please wait..."); graph->computePatterns (anInfoBox); freeInfoBox (); sprintf (temp, "Operation completed: %d patterns found.", graph->patternsNumber); displayDialogBox (mainInterface, "Search patterns", "Nest2", temp, "Continue"); displayCurrentPattern (); return simpleSignal; /* pour lui dire de mettre a jour les fitness */ } if (coherenceButton->manageEvent (report) == buttonPressed) { displayAbortableInfoBox (mainInterface, "Pattern matching", "Nest2", "Pattern matching is running, please wait..."); graph->computePatternMatching (anInfoBox); freeInfoBox (); return simpleSignal; /* pour lui dire de mettre a jour les fitness */ } bar1->manageEvent (report); bar2->manageEvent (report); patternText->manageEvent (report); if (incButton->manageEvent (report) == buttonPressed) { if (currentPatternId < graph->patternsNumber-1) { currentPatternId++; displayCurrentPattern (); } } if (decButton->manageEvent (report) == buttonPressed) { if (currentPatternId > 0) { currentPatternId--; displayCurrentPattern (); } } if (patternWindow->manageEvent (report) == mustBeRefreshed) { displayCurrentPattern (); } return noAction; } void PatternInterface::updatePatternText () { char temp[256]; if (graph->patternsNumber == 0) { sprintf (temp, " No pattern"); } else { sprintf (temp, "Pattern %d of %d", currentPatternId+1, graph->patternsNumber); } patternText->change (temp); } void PatternInterface::refresh () { closeButton->refresh (); searchButton->refresh (); coherenceButton->refresh (); bar1->refresh (); bar2->refresh (); patternText->refresh (); incButton->refresh (); decButton->refresh (); if (patternWindow->shouldBeRefreshed ()) displayCurrentPattern (); } void PatternInterface::displayCurrentPattern () { int i, j, k; Pattern* pattern; updatePatternText (); if (graph->patternsNumber > 0) { if (graph->patternList != NULL) { if (graph->patternList[currentPatternId] != NULL) { pattern = graph->patternList[currentPatternId]; currentPattern->clearWithNoChecking (); currentPattern->clearWithNoChecking (); for (i=0; i<(int)simulation->archSize; i++) { for (j=0; j<(int)simulation->archSize; j++) { for (k=0; k<(int)simulation->archSize; k++) { currentPattern ->setCellWithNoChecking (i, j, k, pattern->getTypeOfCell (i, j, k)); } } } view3d->resize (); // view3d->change_zoom (1); } view3d->drawNet (0, 0); /* 0, car vue pas coupee */ view3d->displayTempScreen (); } } }