/****************************************************************** * * * 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 : EditInt.c Component : edition interface Fonctionality : contains methods for objects refering to the colony's edition interface ******************************************************************/ #include "EditInt.h" #include "view3d.h" #include "config.h" EditInterface::EditInterface (Interface* theMainInterface, int x0, int y0, char* windowLabel, char* iconLabel, Display* aDisplay, Simulation* aSimulation) : Interface (x0, y0, 610, 630, 1, windowLabel, iconLabel, aDisplay) { position org, dest; /* USELESS char temp[100];*/ mainInterface = theMainInterface; acceptButton = new Button (this, 480, 10, 110, 25, "Accept", centerJustified, enabled); cancelButton = new Button (this, 480, 40, 110, 25, "Cancel", centerJustified, enabled); parametersButton = new Button (this, 480, 70, 110, 25, "Parameters", centerJustified, enabled); strcpy (ruleNameText, aSimulation->name); strcpy (ruleFileNameText, aSimulation->fileName); strcpy (rulePathNameText, aSimulation->pathName); ruleName = new TextInput (this, 20, 10, 28, "Colony name: ", ruleNameText, enabled); ruleFileName = new TextInput (this, 20, 35, 30, "File name: ", ruleFileNameText, enabled); rulePathName = new TextInput (this, 20, 60, 30, "Path name: ", rulePathNameText, enabled); if (aSimulation->isSimulated) { ruleNumber = new TextWidget (this, 365, 120, "Rule -- of -- (--% used) "); } else { ruleNumber = new TextWidget (this, 390, 120, "Rule -- of -- "); } editWindow = new GraphicWindow (this, 10, 95, 310, 440, enabled, ButtonPressMask | ExposureMask, Black); rule3dView = new GraphicWindow (this, 330, 265, 270, 270, enabled, ExposureMask, Black); rule3dIcon = new GraphicWindow (this, 500, 155, 100, 100, enabled, ExposureMask, Black); bar1 = new HorizontalBar (this, 10, 550, 585); bar2 = new HorizontalBar (this, 10, 585, 585); bar3 = new HorizontalBar (this, 330, 110, 270); bar4 = new HorizontalBar (this, 330, 140, 270); bar5 = new HorizontalBar (this, 330, 220, 160); bar6 = new HorizontalBar (this, 330, 255, 160); upButton = new UpArrow (this, 10, 555 , enabled); downButton = new DownArrow (this, 40, 555 , enabled); incPhiButton = new UpArrow (this, 340, 225 , enabled, continuePressing); decPhiButton = new DownArrow (this, 370, 225 , enabled, continuePressing); incTetaButton = new LeftArrow (this, 400, 225 , enabled, continuePressing); decTetaButton = new RightArrow (this, 435, 225 , enabled, continuePressing); firstButton = new Button (this, 425, 557, 80, 25, "First", centerJustified, enabled); lastButton = new Button (this, 515, 557, 80, 25, "Last", centerJustified, enabled); addButton = new Button (this, 10, 595, 110, 25, "Add", centerJustified, enabled); deleteButton = new Button (this, 130, 595, 110, 25, "Remove", centerJustified, enabled); insertButton = new Button (this, 250, 595, 110, 25, "Insert", centerJustified, enabled); newRuleButton = new Button (this, 370, 595, 110, 25, "New rule", centerJustified, enabled); newColonyButton = new Button (this, 490, 595, 110, 25, "New col.", centerJustified, enabled); currentArch = new Architecture (3, aSimulation->simuType); aView = new View (display, rule3dView->win, *gc, rule3dIcon->win, color, displayMode, width, height, fontInfo, defaultDepth, currentArch, aSimulation->simuType, this->win); /* en fait, on met ce qu'on veut ici */ org = init_position (); org.x = 5; org.y = 3; org.z = 2; dest = init_position (); aView->init_view (dest, org, 50, 20, 50, 50); aView->translate (-175, -40); aView->unsetAxes (); alreadyComputed = 0; modifiedSimulation = aSimulation; currentRule = new Rule (modifiedSimulation->simuType); modifiedRuleArray = new RuleArray (maxRules, modifiedSimulation->simuType); modifiedRuleArray->setFromOtherRuleArray (aSimulation->simulationRuleArray); if (modifiedRuleArray->getElementsNb ()> 0) { currentIndex = 0; modifiedRuleArray->get (currentIndex, currentRule); setArchFromRule (); updateRuleNumber (); } /* init of random generation type enumeration */ randomGenerationTypeEnum.add ("PseudoRandom"); randomGenerationTypeEnum.add ("ConnexityConstraint"); randomGenerationTypeEnum.add ("SpacialCorrelation"); randomGenerationTypeEnum.add ("ProbabilistTemplates"); randomGenerationTypeEnum.setDefault (defaultRandomGenerationType); /* init of default parameters for generation */ pRedCell = defaultPRedCell; pYellowCell = defaultPYellowCell; averageRuleNb = defaultAverageRuleNb; sdRuleNb = defaultSdRuleNb; randomGenerationType = defaultRandomGenerationType; } EditInterface::~EditInterface () { delete acceptButton; delete cancelButton; delete parametersButton; delete ruleName; delete ruleFileName; delete rulePathName; delete ruleNumber; delete editWindow; delete rule3dView; delete rule3dIcon; delete bar1; delete bar2; delete bar3; delete bar4; delete bar5; delete bar6; delete upButton; delete downButton; delete incPhiButton; delete decPhiButton; delete incTetaButton; delete decTetaButton; delete firstButton; delete lastButton; delete addButton; delete deleteButton; delete insertButton; delete newRuleButton; delete newColonyButton; delete currentArch; delete aView; delete modifiedRuleArray; delete currentRule; } actionType EditInterface::manageInterface (XEvent report) { actionType action; /* USELESS char temp[100];*/ double oldPRedCell; double oldPYellowCell; double oldAverageRuleNb; double oldSdRuleNb; if (acceptButton->manageEvent (report) == buttonPressed) { if (modifiedSimulation->isDisplayed) { displayDialogBox (mainInterface, "Error", "Nest2", "Please close the visualisation before.", "Continue"); } else { modifiedSimulation->simulationRuleArray->setFromOtherRuleArray (modifiedRuleArray); modifiedSimulation->ruleNumber = modifiedRuleArray->getElementsNb (); // modifiedSimulation->archSize = 0; if (modifiedSimulation->isSimulated == BTrue) { delete modifiedSimulation->simulationArchitecture; modifiedSimulation->isSimulated = BFalse; modifiedSimulation->isPreviewed = BFalse; } modifiedSimulation->mark = 0.0; /* modifiedSimulation->simuType = cubic; */ /* on recupere les valeurs des entrees de chaines */ strcpy (ruleNameText, ruleName->returnCharValue ()); strcpy (ruleFileNameText, ruleFileName->returnCharValue ()); strcpy (rulePathNameText, rulePathName->returnCharValue ()); strncpy (modifiedSimulation->name, ruleNameText, 23); modifiedSimulation->name[23] = '\0'; strncpy (modifiedSimulation->fileName, ruleFileNameText, 20); modifiedSimulation->fileName[20] = '\0'; strncpy (modifiedSimulation->pathName, rulePathNameText, 80); modifiedSimulation->pathName[80] = '\0'; modifiedSimulation->isSaved = BFalse; return endInterfaceAndSave; } } if (cancelButton->manageEvent (report) == buttonPressed) { return endInterface; } if (parametersButton->manageEvent (report) == buttonPressed) { oldPRedCell = pRedCell; oldPYellowCell = pYellowCell; oldAverageRuleNb = averageRuleNb; oldSdRuleNb = sdRuleNb; displayInputBox (mainInterface, "Generation parameters", "nest2", 6, 43); addDoubleInput (" Red Cell probability ", 10, &pRedCell); addDoubleInput (" Yellow Cell probability ", 10, &pYellowCell); addDoubleInput (" Average rules number ", 10, &averageRuleNb); addDoubleInput ("Rules number st. deviation ", 10, &sdRuleNb); addEnumInput ( " Random generation", 20, &randomGenerationTypeEnum); if (manageInputBox ()) { /* cancelled operation */ pRedCell = oldPRedCell ; pYellowCell = oldPYellowCell; averageRuleNb = oldAverageRuleNb; sdRuleNb = oldSdRuleNb; } else { randomGenerationType = (RandomGenerationType)(randomGenerationTypeEnum.defaultValue ()); } } ruleName->manageEvent (report); ruleFileName->manageEvent (report); rulePathName->manageEvent (report); ruleNumber->manageEvent (report); action = editWindow->manageEvent (report); if (action == mustBeRefreshed) { redrawEditWindow (); } else if (action == button1Pressed) { updateRule (report.xbutton.x, report.xbutton.y, 1); } else if (action == button2Pressed) { updateRule (report.xbutton.x, report.xbutton.y, 2); } else if (action == button3Pressed) { updateRule (report.xbutton.x, report.xbutton.y, 3); } if (rule3dView->manageEvent (report) == mustBeRefreshed) { displayView3d (); } if (rule3dIcon->manageEvent (report) == mustBeRefreshed) { aView->displayViewIcon (); } bar1->manageEvent (report); bar2->manageEvent (report); bar3->manageEvent (report); bar4->manageEvent (report); bar5->manageEvent (report); bar6->manageEvent (report); if (upButton->manageEvent (report) == buttonPressed) { if (currentIndex < (int)(modifiedRuleArray->getElementsNb ()-1)) { currentIndex++; modifiedRuleArray->get (currentIndex, currentRule); setArchFromRule (); alreadyComputed = 0; displayView3d (); updateRuleNumber (); redrawEditWindow (); } } if (downButton->manageEvent (report) == buttonPressed) { if (currentIndex > 0) { currentIndex--; modifiedRuleArray->get (currentIndex, currentRule); setArchFromRule (); alreadyComputed = 0; displayView3d (); updateRuleNumber (); redrawEditWindow (); } } action = incPhiButton->manageEvent (report); if ((action == buttonPressed) || (action == endOfPression)) { if (aView->get_phi () < M_PI/2) { alreadyComputed = 0; aView->change_phi (1); aView->displayViewIcon (); } if (action == endOfPression) displayView3d (); } action = decPhiButton->manageEvent (report); if ((action == buttonPressed) || (action == endOfPression)) { if (aView->get_phi () > -M_PI/2) { alreadyComputed = 0; aView->change_phi (0); aView->displayViewIcon (); } if (action == endOfPression) displayView3d (); } action = incTetaButton->manageEvent (report); if ((action == buttonPressed) || (action == endOfPression)) { alreadyComputed = 0; aView->change_teta (1); aView->displayViewIcon (); if (action == endOfPression) displayView3d (); } action = decTetaButton->manageEvent (report); if ((action == buttonPressed) || (action == endOfPression)) { alreadyComputed = 0; aView->change_teta (0); aView->displayViewIcon (); if (action == endOfPression) displayView3d (); } if (firstButton->manageEvent (report) == buttonPressed) { currentIndex = 0; modifiedRuleArray->get (currentIndex, currentRule); setArchFromRule (); alreadyComputed = 0; displayView3d (); updateRuleNumber (); redrawEditWindow (); } if (lastButton->manageEvent (report) == buttonPressed) { currentIndex = modifiedRuleArray->getElementsNb ()-1; modifiedRuleArray->get (currentIndex, currentRule); setArchFromRule (); alreadyComputed = 0; displayView3d (); updateRuleNumber (); redrawEditWindow (); } if (addButton->manageEvent (report) == buttonPressed) { manageAdd (); currentIndex = modifiedRuleArray->getElementsNb ()-1; modifiedRuleArray->get (currentIndex, currentRule); setArchFromRule (); alreadyComputed = 0; displayView3d (); updateRuleNumber (); redrawEditWindow (); } if (deleteButton->manageEvent (report) == buttonPressed) { if (currentIndex == (int)modifiedRuleArray->getElementsNb ()-1) { manageDelete (); currentIndex = modifiedRuleArray->getElementsNb ()-1; modifiedRuleArray->get (currentIndex, currentRule); setArchFromRule (); alreadyComputed = 0; displayView3d (); updateRuleNumber (); redrawEditWindow (); } else { manageDelete (); modifiedRuleArray->get (currentIndex, currentRule); setArchFromRule (); alreadyComputed = 0; displayView3d (); updateRuleNumber (); redrawEditWindow (); } } if (insertButton->manageEvent (report) == buttonPressed) { manageInsert (); } if (newRuleButton->manageEvent (report) == buttonPressed) { manageNewRule (); } if (newColonyButton->manageEvent (report) == buttonPressed) { manageNewColony (); } return noAction; } void EditInterface::refresh () { if (editWindow->shouldBeRefreshed ()) redrawEditWindow (); if (rule3dView->shouldBeRefreshed ()) displayView3d (); if (rule3dIcon->shouldBeRefreshed ()) aView->displayViewIcon (); acceptButton->refresh (); cancelButton->refresh (); parametersButton->refresh (); ruleName->refresh (); ruleFileName->refresh (); rulePathName->refresh (); ruleNumber->refresh (); bar1->refresh (); bar2->refresh (); bar3->refresh (); bar4->refresh (); bar5->refresh (); bar6->refresh (); upButton->refresh (); downButton->refresh (); incPhiButton->refresh (); decPhiButton->refresh (); incTetaButton->refresh (); decTetaButton->refresh (); firstButton->refresh (); lastButton->refresh (); addButton->refresh (); deleteButton->refresh (); insertButton->refresh (); newRuleButton->refresh (); newColonyButton->refresh (); } void EditInterface::displayView3d () { aView->drawNet (alreadyComputed, 0); /* 0, car vue pas coupee */ aView->displayTempScreen (); alreadyComputed = 1; } void EditInterface::setArchFromRule () { int i, j, k; /* cubic simulation processing */ if (modifiedSimulation->simuType == cubic) { for (k=0; k<3; k++) { for (j=0; j<3; j++) { for (i=0; i<3; i++) { currentArch->setCell (i,j,k, currentRule->get ((2-i),j, 2-k), -3); /* le -3 signifie que l'on ne construit pas le graphe (et pour cause !!!) */ } } } } /* hexa simulation processing */ else if (modifiedSimulation->simuType == hexa) { for (k=0; k<3; k++) { currentArch->setCell (1, 1, 2-k, currentRule->get (k, 0), -3); currentArch->setCell (1, 0, 2-k, currentRule->get (k, 1), -3); currentArch->setCell (0, 0, 2-k, currentRule->get (k, 2), -3); currentArch->setCell (0, 1, 2-k, currentRule->get (k, 3), -3); currentArch->setCell (1, 2, 2-k, currentRule->get (k, 4), -3); currentArch->setCell (2, 1, 2-k, currentRule->get (k, 5), -3); currentArch->setCell (2, 0, 2-k, currentRule->get (k, 6), -3); currentArch->setCell (0, 2, 2-k, EMPTY, -3); currentArch->setCell (2, 2, 2-k, EMPTY, -3); } } } void EditInterface::redrawEditWindow () { int i, j, k; XPoint pts[7]; unsigned int cx, cy; XClearWindow (display, editWindow->win); /* processing for cubic structures */ if (modifiedSimulation->simuType == cubic) { XSetLineAttributes (display, *gc, 2, LineSolid, CapButt, JoinRound); XSetForeground (display, *gc, color[White]); for (i=0; i<3; i++) { XDrawRectangle (display, editWindow->win, *gc, 90, 13+i*140, 129, 129); for (j=1; j<3; j++) { XDrawRectangle (display, editWindow->win, *gc, 90, 13+i*140, 43*j, 43*j); XDrawRectangle (display, editWindow->win, *gc, 90+43*j, 13+i*140+43*j, 43*(3-j), 43*(3-j)); } } XSetLineAttributes (display, *gc, 1, LineSolid, CapButt, JoinRound); for (k=0; k<3; k++) { for (j=0; j<3; j++) { for (i=0; i<3; i++) { if (currentRule->get (i,j,k) != EMPTY) { if (currentRule->get (i,j,k) == RED) { /* RED */ XSetForeground (display, *gc, color[Red]); } else if (currentRule->get (i,j,k) == YELLOW) { /* YELLOW */ XSetForeground (display, *gc, color[Gold]); } else if (currentRule->get (i,j,k) == BLUE) { /* BLUE */ XSetForeground (display, *gc, color[Blue]); } XFillRectangle (display, editWindow->win, *gc, 91+43*i, 14+k*140+j*43, 42, 42); } } } } } /* processing for hexa structures */ else { XSetLineAttributes (display, *gc, 2, LineSolid, CapButt, JoinRound); for (i=0; i<3; i++) { /* centre de l'hexagone en construction */ cx = 155; cy = 77+i*143; /* calcul des differents points */ setHexa (pts, cx, cy); /* positionnement couleur */ if (currentRule->get (i, 0) == EMPTY) { XSetForeground (display, *gc, color[Black]); } else if (currentRule->get (i, 0) == RED) { XSetForeground (display, *gc, color[Red]); } else if (currentRule->get (i, 0) == YELLOW) { XSetForeground (display, *gc, color[Gold]); } else if (currentRule->get (i, 0) == BLUE) { XSetForeground (display, *gc, color[Blue]); } /* dessin de l'hexagone */ XFillPolygon(display, editWindow->win, *gc, pts, 7, Convex, CoordModeOrigin); XSetForeground (display, *gc, color[White]); XDrawLines(display, editWindow->win, *gc, pts, 7, CoordModeOrigin); for (j=0; j<6; j++) { /* calcul des differents points */ setHexa (pts, cx+(int)(editorHexaSize*2*cos(pi/6)*cos(pi/2+j*pi/3)), cy+(int)(editorHexaSize*2*cos(pi/6)*sin(pi/2+j*pi/3))); /* positionnement couleur */ if (currentRule->get (i, j+1) == EMPTY) { /* 2-i */ XSetForeground (display, *gc, color[Black]); } else if (currentRule->get (i, j+1) == RED) { /* 2-i */ XSetForeground (display, *gc, color[Red]); } else if (currentRule->get (i, j+1) == YELLOW) { /* 2-i */ XSetForeground (display, *gc, color[Gold]); } else if (currentRule->get (i, j+1) == BLUE) { /* 2-i */ XSetForeground (display, *gc, color[Blue]); } /* dessin de l'hexagone */ XFillPolygon(display, editWindow->win, *gc, pts, 7, Convex, CoordModeOrigin); XSetForeground (display, *gc, color[White]); XDrawLines(display, editWindow->win, *gc, pts, 7, CoordModeOrigin); } } XSetLineAttributes (display, *gc, 1, LineSolid, CapButt, JoinRound); } } void EditInterface::setHexa (XPoint* pts, unsigned int x, unsigned int y) { int i; for (i=0; i<7; i++) { pts[i].x = x+(int)(editorHexaSize*cos (i*pi/3)); pts[i].y = y+(int)(editorHexaSize*sin (i*pi/3)); } } void EditInterface::updateRule (unsigned int x, unsigned int y, int button) { int i,j,k; typeOfCell aCellType; typeOfCell oldCellType; unsigned int tx, ty, cx, cy; int selectedPlan, selectedNb; XPoint pts[7]; /* a modifier pour une cellule bleue */ /* if (button == 1) { aCellType = RED; } else if (button == 2) { aCellType = YELLOW; } else { aCellType = EMPTY; } */ XSetLineAttributes (display, *gc, 2, LineSolid, CapButt, JoinRound); /* cubic structures processing */ if (modifiedSimulation->simuType == cubic) { if (x<91 || x>219 || y<14 || y>432) { /* not in range */ //printf ("not in range\n"); } else { y = y - 13; x = x - 90; if (y<140) { k = 2; } else if (y<280) { k = 1; y = y-140; } else { k = 0; y = y-280; } if (y<43) { j = 0; } else if (y<86) { j = 1; } else { j = 2; } if (x<43) { i = 0; } else if (x<86) { i = 1; } else { i = 2; } oldCellType = currentRule->get (i,j,2-k); if (button == 1) { if (oldCellType != EMPTY) { aCellType = (typeOfCell)(oldCellType-1); } else { aCellType = BLUE; } } else if (button == 2) { aCellType = EMPTY; } else if (button == 3) { if (oldCellType != BLUE) { aCellType = (typeOfCell)(oldCellType+1); } else { aCellType = EMPTY; } } if (!((i==1) && (j==1) && (k==1) && (aCellType == EMPTY))) { /* center cell must not be empty */ currentRule->set (i, j, 2-k, aCellType); setArchFromRule (); alreadyComputed = 0; displayView3d (); if (aCellType == RED) { XSetForeground (display, *gc, color[Red]); } else if (aCellType == YELLOW) { XSetForeground (display, *gc, color[Gold]); } else if (aCellType == BLUE) { XSetForeground (display, *gc, color[Blue]); } else { XSetForeground (display, *gc, color[Black]); } XSetLineAttributes (display, *gc, 2, LineSolid, CapButt, JoinRound); XFillRectangle (display, editWindow->win, *gc, 91+43*i, 14+(2-k)*140+j*43, 41, 41); XSetLineAttributes (display, *gc, 1, LineSolid, CapButt, JoinRound); modifiedRuleArray->set (currentIndex, *currentRule); } } } /* hexa structures processing */ else if (modifiedSimulation->simuType == hexa) { selectedPlan = -1; selectedNb = -1; for (i=0; i<3; i++) { if ( (double)((x-155)*(x-155)+(y-77-i*143)*(y-77-i*143)) < (editorHexaSize*cos(pi/6)*3*editorHexaSize*cos(pi/6)*3)) { if ( (double)((x-155)*(x-155)+(y-77-i*143)*(y-77-i*143)) < (editorHexaSize*cos(pi/6)*editorHexaSize*cos(pi/6))) { selectedPlan = i; selectedNb = 0; setHexa (pts, 155, 77+i*143); } else { for (j=0; j<6; j++) { cx = 155; cy = 77+i*143; tx = cx+(int)(editorHexaSize*2*cos(pi/6)*cos(pi/2+j*pi/3)); ty = cy+(int)(editorHexaSize*2*cos(pi/6)*sin(pi/2+j*pi/3)); if ( (double)((x-tx)*(x-tx)+(y-ty)*(y-ty)) < (editorHexaSize*cos(pi/6)*editorHexaSize*cos(pi/6)) ) { selectedPlan = i; selectedNb = j+1; setHexa (pts, tx, ty); } } } } } oldCellType = currentRule->get (selectedPlan, selectedNb); if (button == 1) { if (oldCellType != EMPTY) { aCellType = (typeOfCell)(oldCellType-1); } else { aCellType = BLUE; } } else if (button == 2) { aCellType = EMPTY; } else if (button == 3) { if (oldCellType != BLUE) { aCellType = (typeOfCell)(oldCellType+1); } else { aCellType = EMPTY; } } if ( !((selectedPlan == 1) && (selectedNb == 0) && (aCellType == EMPTY))) { /* center cell must not be empty */ if (selectedPlan != -1) { currentRule->set (selectedPlan, selectedNb, aCellType); setArchFromRule (); alreadyComputed = 0; displayView3d (); if (aCellType == RED) { XSetForeground (display, *gc, color[Red]); } else if (aCellType == YELLOW) { XSetForeground (display, *gc, color[Gold]); } else if (aCellType == BLUE) { XSetForeground (display, *gc, color[Blue]); } else { XSetForeground (display, *gc, color[Black]); } XSetLineAttributes (display, *gc, 2, LineSolid, CapButt, JoinRound); XFillPolygon(display, editWindow->win, *gc, pts, 7, Convex, CoordModeOrigin); XSetForeground (display, *gc, color[White]); XDrawLines(display, editWindow->win, *gc, pts, 7, CoordModeOrigin); XSetLineAttributes (display, *gc, 1, LineSolid, CapButt, JoinRound); modifiedRuleArray->set (currentIndex, *currentRule); } } } XSetLineAttributes (display, *gc, 1, LineSolid, CapButt, JoinRound); } void EditInterface::updateRuleNumber () { char temp[100]; int n1, n2; if (modifiedSimulation->isSimulated) { n1 = modifiedSimulation->simulationArchitecture->ruleOccurs[currentIndex]; n2 = modifiedSimulation->simulationArchitecture->cellsNumber; sprintf (temp, "Rule %d of %d (%d%% used) ", currentIndex+1, modifiedRuleArray->getElementsNb (), (int) ((double)n1*100/ (double)n2)); ruleNumber->change (temp); } else { sprintf (temp, "Rule %d of %d ", currentIndex+1, modifiedRuleArray->getElementsNb ()); ruleNumber->change (temp); } } void EditInterface::manageAdd () { int x, y, z; Rule aRule (modifiedSimulation->simuType); for (x=0; x<3; x++) { for (y=0; y<3; y++) { for (z=0; z<3; z++) { aRule.set (x,y,z,EMPTY); } } } aRule.set (1,1,1,RED); modifiedRuleArray->add (aRule); /* currentIndex = 0; */ modifiedRuleArray->get (currentIndex, currentRule); setArchFromRule (); updateRuleNumber (); redrawEditWindow (); displayView3d (); } void EditInterface::manageDelete () { if (modifiedRuleArray->getElementsNb () == 1) { displayDialogBox (mainInterface, "Error", "Nest2", "You can't delete the last rule.", "Continue"); } else { modifiedRuleArray->del (currentIndex); if (currentIndex >= (int)modifiedRuleArray->getElementsNb()) { currentIndex--; } setArchFromRule (); updateRuleNumber (); redrawEditWindow (); displayView3d (); } } void EditInterface::manageInsert () { int x, y, z; Rule aRule (modifiedSimulation->simuType); for (x=0; x<3; x++) { for (y=0; y<3; y++) { for (z=0; z<3; z++) { aRule.set (x,y,z,EMPTY); } } } aRule.set (1,1,1,RED); modifiedRuleArray->insert (aRule, currentIndex); modifiedRuleArray->get (currentIndex, currentRule); setArchFromRule (); updateRuleNumber (); redrawEditWindow (); displayView3d (); } void EditInterface::manageNewRule () { Rule aRule (modifiedSimulation->simuType); aRule.randomGenerate (pRedCell, pYellowCell, (RandomGenerationType) randomGenerationTypeEnum.defaultValue ()); modifiedRuleArray->set (currentIndex, aRule); modifiedRuleArray->get (currentIndex, currentRule); alreadyComputed = 0; setArchFromRule (); updateRuleNumber (); redrawEditWindow (); displayView3d (); } void EditInterface::manageNewColony () { modifiedRuleArray ->randomGenerate (pRedCell, pYellowCell, averageRuleNb, sdRuleNb, (RandomGenerationType) randomGenerationTypeEnum.defaultValue ()); currentIndex = 0; modifiedRuleArray->get (currentIndex, currentRule); alreadyComputed = 0; setArchFromRule (); updateRuleNumber (); redrawEditWindow (); displayView3d (); }