Exemple #1
0
void TreeNodeTest::maxWinLeaf()
{
  for ( int i = 1; i <= 3; i++ )
    game_m.addComputerMove(i);
    
  MaxNode current(game_m);

  CPPUNIT_ASSERT( -1 == current.getMove() );
  CPPUNIT_ASSERT(  1 == current.getValue() );

  game_m.reset();

  game_m.addComputerMove(4);
  game_m.addComputerMove(5);
  game_m.addComputerMove(6);

  MaxNode current2(game_m);

  CPPUNIT_ASSERT( -1 == current2.getMove() ); 
  CPPUNIT_ASSERT(  1 == current2.getValue() );
}
void MobileSimulator::MouseMotionEvent(Vec2i screenCoordinates)
{
	Vector2 pos = MathUtil::ScreenToWorld(screenCoordinates);
	_fingerGhost1->SetPosition(pos);
	_fingerGhost2->SetPosition(-pos);

	if (_mouseDown)
	{
		//move touch(es)
		TouchList *tl = &TouchListener::GetTouchList();
		if (tl->size() > 0)
		{
			(*tl)[0]->CurrentPoint = screenCoordinates;
			if ( (*tl)[0]->MotionStartTime < 0.0f )
			{
				(*tl)[0]->MotionStartTime = theWorld.GetCurrentTimeSeconds();
			}
		}
		if (tl->size() > 1)
		{
			Vector2 negCoordsVec = MathUtil::WorldToScreen(-pos);
			Vec2i negCoords(negCoordsVec.X, negCoordsVec.Y);
			(*tl)[1]->CurrentPoint = negCoords;
			if ( (*tl)[1]->MotionStartTime < 0.0f )
			{
				(*tl)[1]->MotionStartTime = theWorld.GetCurrentTimeSeconds();
			}

			Touch* t1 = (*tl)[0];
			Touch* t2 = (*tl)[1];

			Vector2 start1(t1->StartingPoint);
			Vector2 current1(t1->CurrentPoint);
			Vector2 start2(t2->StartingPoint);
			Vector2 current2(t2->CurrentPoint);

			Vector2 initialVector = start2 - start1;
			Vector2 currentVector = current2 - current1;

			Vector2 initNorm = Vector2::Normalize(initialVector);
			Vector2 currentNorm = Vector2::Normalize(currentVector);
			float radiansRotated = acos(Vector2::Dot(initNorm, currentNorm));

			if (!_multiGestureOngoing)
			{					
				Vector2 motion = current1 - start1;

				if (motion.LengthSquared() >= (MULTI_MIN_DISTANCE * MULTI_MIN_DISTANCE) )
				{
					_multiGestureOngoing = true;
					
					// figure out if it's a rotate or a pinch
					if (radiansRotated > MULTI_ROTATE_ANGLE)
					{
						_gestureType = ROTATE;
					}
					else
					{
						_gestureType = PINCH;
					}
				}
			}

			if (_multiGestureOngoing)
			{
				GestureData gd;
				gd.Velocity = 0.0f; // don't want to store all the extra datums
									//  needed to actually calculate this

				if      (_gestureType == ROTATE)
				{
					float cross = Vector2::Cross(initNorm, currentNorm);
					if (cross > 0.0f)
					{
						radiansRotated = -radiansRotated;
					}
					gd.GestureMagnitude = radiansRotated;
					theSwitchboard.Broadcast(new TypedMessage<GestureData>("MultiTouchRotate", gd));
				}
				else if (_gestureType == PINCH)
				{
					gd.GestureMagnitude = currentVector.Length() / initialVector.Length();
					theSwitchboard.Broadcast(new TypedMessage<GestureData>("MultiTouchPinch", gd));	
				}
			}
		}
	}
}
Exemple #3
0
int Gui::drawPage(
  LGraphicsView  *view,
  QGraphicsScene *scene,
  Steps          *steps,
  int             stepNum,
  QString const  &addLine,
  Where          &current,
  QStringList    &csiParts,
  QStringList    &pliParts,
  bool            isMirrored,
  QHash<QString, QStringList> &bfx,
  bool            printing,
  bool            bfxStore2,
  QStringList    &bfxParts,
  bool            calledOut)
{
  bool        global = true;
  QString     line;
  Callout    *callout     = NULL;
  Range      *range       = NULL;
  Step       *step        = NULL;
  bool        pliIgnore   = false;
  bool        partIgnore  = false;
  bool        synthBegin  = false;
  bool        multiStep   = false;
  bool        partsAdded  = false;
  bool        coverPage   = false;
  bool        bfxStore1   = false;
  bool        bfxLoad     = false;
  int         numLines = ldrawFile.size(current.modelName);
  bool        firstStep   = true;
  
  steps->isMirrored = isMirrored;
  
  QList<InsertMeta> inserts;
  
  Where topOfStep = current;
  Rc gprc = OkRc;
  Rc rc;

  statusBar()->showMessage("Processing " + current.modelName);

  page.coverPage = false;

  QStringList calloutParts;

  /*
   * do until end of page
   */
  for ( ; current <= numLines; current++) {

    Meta   &curMeta = callout ? callout->meta : steps->meta;

    QStringList tokens;

    // If we hit end of file we've got to note end of step

    if (current >= numLines) {
      line.clear();
      gprc = EndOfFileRc;
      tokens << "0";
      
      // not end of file, so get the next LDraw line 
     
    } else {
      line = ldrawFile.readLine(current.modelName,current.lineNumber);
      split(line,tokens);
    }
    
    if (tokens.size() == 15 && tokens[0] == "1") {
      
      QString color = tokens[1];
      QString type  = tokens[tokens.size()-1];

      csiParts << line;
      partsAdded = true;

      /* since we have a part usage, we have a valid step */

      if (step == NULL) {
        if (range == NULL) {
          range = newRange(steps,calledOut);
          steps->append(range);
        }

        step = new Step(topOfStep,
                        range,
                        stepNum,
                        curMeta,
                        calledOut,
                        multiStep);

        range->append(step);
      }

      /* addition of ldraw parts */

      if (curMeta.LPub.pli.show.value()
          && ! pliIgnore 
          && ! partIgnore 
          && ! synthBegin) {
        QString colorType = color+type;
        if (! isSubmodel(type) || curMeta.LPub.pli.includeSubs.value()) {
          if (bfxStore2 && bfxLoad) {
            bool removed = false;
            for (int i = 0; i < bfxParts.size(); i++) {
              if (bfxParts[i] == colorType) {
                bfxParts.removeAt(i);
                removed = true;
                break;
              }
            }
            if ( ! removed) {
              pliParts << Pli::partLine(line,current,steps->meta);
            }
          } else {
            pliParts << Pli::partLine(line,current,steps->meta);
          }
        }
        if (bfxStore1) {
          bfxParts << colorType;
        }
      }

      /* if it is a sub-model, then process it */

      if (ldrawFile.contains(type) && callout) {

        /* we are a callout, so gather all the steps within the callout */
        /* start with new meta, but no rotation step */

        if (callout->bottom.modelName != type) {

          Where current2(type,0);
          skipHeader(current2);          
          callout->meta.rotStep.clear();
          SubmodelStack tos(current.modelName,current.lineNumber,stepNum);
          callout->meta.submodelStack << tos;

          Meta saveMeta = callout->meta;
          callout->meta.LPub.pli.constrain.resetToDefault();

          step->append(callout);

          calloutParts.clear();
          QStringList csiParts2;

          QHash<QString, QStringList> calloutBfx;

          int rc;

          rc = drawPage(
                 view,
                 scene,
                 callout,
                 1,
                 line,
                 current2,
                 csiParts2,
                 calloutParts,
                 ldrawFile.mirrored(tokens),
                 calloutBfx,
                 printing,
                 bfxStore2,
                 bfxParts,
                 true);

          callout->meta = saveMeta;

          if (callout->meta.LPub.pli.show.value() &&
            ! callout->meta.LPub.callout.pli.perStep.value() &&
            ! pliIgnore && ! partIgnore && ! synthBegin) {

            pliParts += calloutParts;
          }

          if (rc != 0) {
            steps->placement = steps->meta.LPub.assem.placement;
            return rc;
          }
        } else {
          callout->instances++;
          pliParts += calloutParts;
        }

        /* remind user what file we're working on */

        statusBar()->showMessage("Processing " + current.modelName);
      }
    } else if (tokens.size() > 0 &&
              (tokens[0] == "2" ||
               tokens[0] == "3" ||
               tokens[0] == "4" ||
               tokens[0] == "5")) {

      csiParts << line;
      partsAdded = true;

      /* we've got a line, triangle or polygon, so add it to the list */
      /* and make sure we know we have a step */

      if (step == NULL) {
        if (range == NULL) {            
          range = newRange(steps,calledOut);
          steps->append(range);
        }

        step = new Step(topOfStep,
                        range,
                        stepNum,
                        steps->meta,
                        calledOut,
                        multiStep);
        range->append(step);
      }

    } else if (tokens.size() > 0 && tokens[0] == "0" || gprc == EndOfFileRc) {
      
      /* must be meta-command (or comment) */
      if (global && tokens.contains("!LPUB") && tokens.contains("GLOBAL")) {
        topOfStep = current;
      } else {
        global = false;
      }

      QString part;

      if (gprc == EndOfFileRc) {
        rc = gprc;
      } else {
        rc = curMeta.parse(line,current,true);
      }

      /* handle specific meta-commands */

      switch (rc) {

        /* toss it all out the window, per James' original plan */
        case ClearRc:
          pliParts.clear();
          csiParts.clear();
          steps->freeSteps();
        break;

        /* Buffer exchange */
        case BufferStoreRc:
          bfx[curMeta.bfx.value()] = csiParts;
          bfxStore1 = true;
          bfxParts.clear();
        break;

        case BufferLoadRc:
          csiParts = bfx[curMeta.bfx.value()];
          bfxLoad = true;
        break;

        case MLCadGroupRc:
          csiParts << line;
        break;
        
        case IncludeRc:
          include(curMeta);
        break;

        /* substitute part/parts with this */

        case PliBeginSub1Rc:
          if (pliIgnore) {
            parseError("Nested PLI BEGIN/ENDS not allowed\n",current);
          } 
          if (steps->meta.LPub.pli.show.value() && 
              ! pliIgnore && 
              ! partIgnore && 
              ! synthBegin) {

            SubData subData = curMeta.LPub.pli.begin.sub.value();
            QString addPart = QString("1 0  0 0 0  0 0 0 0 0 0 0 0 0 %1") .arg(subData.part);
            pliParts << Pli::partLine(addPart,current,curMeta);
          }

          if (step == NULL) {
            if (range == NULL) {
              range = newRange(steps,calledOut);
              steps->append(range);
            }
            step = new Step(topOfStep,
                            range,
                            stepNum,
                            curMeta,
                            calledOut,
                            multiStep);
            range->append(step);
          }
          pliIgnore = true;
        break;

        /* substitute part/parts with this */
        case PliBeginSub2Rc:
          if (pliIgnore) {
            parseError("Nested BEGIN/ENDS not allowed\n",current);
          } 
          if (steps->meta.LPub.pli.show.value() &&
              ! pliIgnore &&
              ! partIgnore &&
              ! synthBegin) {

            SubData subData = curMeta.LPub.pli.begin.sub.value();
            QString addPart = QString("1 %1  0 0 0  0 0 0 0 0 0 0 0 0 %2") .arg(subData.color) .arg(subData.part);
            pliParts << Pli::partLine(addPart,current,curMeta);
          }

          if (step == NULL) {
            if (range == NULL) {
              range = newRange(steps,calledOut);
              steps->append(range);
            }
            step = new Step(topOfStep,
                            range,
                            stepNum,
                            curMeta,
                            calledOut,
                            multiStep);
            range->append(step);
          }
          pliIgnore = true;
        break;

        /* do not put subsequent parts into PLI */
        case PliBeginIgnRc:
          if (pliIgnore) {
            parseError("Nested BEGIN/ENDS not allowed\n",current);
          } 
          pliIgnore = true;
        break;
        case PliEndRc:
          if ( ! pliIgnore) {
            parseError("PLI END with no PLI BEGIN",current);
          }
          pliIgnore = false;
        break;

        /* discard subsequent parts, and don't create CSI's for them */
        case PartBeginIgnRc:
        case MLCadSkipBeginRc:
          if (partIgnore) {
            parseError("Nested BEGIN/ENDS not allowed\n",current);
          } 
          partIgnore = true;
        break;

        case PartEndRc:
        case MLCadSkipEndRc:
          if (partIgnore) {
            parseError("Ignore ending with no ignore begin",current);
          }
          partIgnore = false;
        break;

        case SynthBeginRc:
          if (synthBegin) {
            parseError("Nested BEGIN/ENDS not allowed\n",current);
          } 
          synthBegin = true;
        break;

        case SynthEndRc:
          if ( ! synthBegin) {
            parseError("Ignore ending with no ignore begin",current);
          }
          synthBegin = false;
        break;


        /* remove a group or all instances of a part type */
        case GroupRemoveRc:
        case RemoveGroupRc:
        case RemovePartRc:
        case RemoveNameRc:
          {
            QStringList newCSIParts;

            if (rc == RemoveGroupRc) {
              remove_group(csiParts,steps->meta.LPub.remove.group.value(),newCSIParts);
            } else if (rc == RemovePartRc) {
              remove_parttype(csiParts, steps->meta.LPub.remove.parttype.value(),newCSIParts);
            } else {
              remove_partname(csiParts, steps->meta.LPub.remove.partname.value(),newCSIParts);
            }
            csiParts = newCSIParts;

            if (step == NULL) {
              if (range == NULL) {
                range = newRange(steps,calledOut);
                steps->append(range);
              }
              step = new Step(topOfStep,
                              range,
                              stepNum,
                              curMeta,
                              calledOut,
                              multiStep);
              range->append(step);
            }
          }
        break;

        case ReserveSpaceRc:
          /* since we have a part usage, we have a valid step */
          if (calledOut || multiStep) {
            step = NULL;
            Reserve *reserve = new Reserve(current,steps->meta.LPub);
            if (range == NULL) {
              range = newRange(steps,calledOut);
              steps->append(range);
            }
            range->append(reserve);
          }
        break;
        
        case InsertCoverPageRc:
          coverPage = true;
          page.coverPage = true;

        case InsertPageRc:
          partsAdded = true;
        break;
        
        case InsertRc:
          inserts.append(curMeta.LPub.insert);  // these are always placed before any parts in step
        break;

        case CalloutBeginRc:
          if (callout) {
            parseError("Nested CALLOUT not allowed within the same file",current);
          } else {
            callout = new Callout(curMeta,view);
            callout->setTopOfCallout(current);
          }
        break;

        case CalloutDividerRc:
          if (range) {
            range->sepMeta = curMeta.LPub.callout.sep;
            range = NULL;
            step = NULL;
          }
        break;

        case CalloutPointerRc:
          if (callout) {
            callout->appendPointer(current,curMeta.LPub.callout);
          }
        break;

        case CalloutEndRc:
          if ( ! callout) {
            parseError("CALLOUT END without a CALLOUT BEGIN",current);
          } else {
            callout->parentStep = step;
            callout->parentRelativeType = step->relativeType;
            callout->pli.clear();
            callout->placement = curMeta.LPub.callout.placement;
            callout->setBottomOfCallout(current);
            callout = NULL;
          }
        break;

        case StepGroupBeginRc:
          if (calledOut) {
            parseError("MULTI_STEP not allowed inside callout models",current);
          } else {
            if (multiStep) {
              parseError("Nested MULTI_STEP not allowed",current);
            }
            multiStep = true;
          }
          steps->relativeType = StepGroupType;
        break;

        case StepGroupDividerRc:
          if (range) {
            range->sepMeta = steps->meta.LPub.multiStep.sep;
            range = NULL;
            step = NULL;
          }
        break;

        /* finished off a multiStep */
        case StepGroupEndRc:
          if (multiStep) {
            // save the current meta as the meta for step group
            // PLI for non-pli-per-step
            if (partsAdded) {
              parseError("Expected STEP before MULTI_STEP END", current);
            }
            multiStep = false;

            if (pliParts.size() && steps->meta.LPub.multiStep.pli.perStep.value() == false) {
              steps->pli.bom = false;
              steps->pli.setParts(pliParts,steps->stepGroupMeta);
              steps->pli.sizePli(&steps->stepGroupMeta, StepGroupType, false);
            }
            pliParts.clear();

            /* this is a page we're supposed to process */

            steps->placement = steps->meta.LPub.multiStep.placement;
            showLine(steps->topOfSteps());
            
            bool endOfSubmodel = stepNum == ldrawFile.numSteps(current.modelName);
            int  instances = ldrawFile.instances(current.modelName,isMirrored);
            addGraphicsPageItems(steps, coverPage, endOfSubmodel,instances, view, scene,printing);
            return HitEndOfPage;
          }
        break;

        /* we're hit some kind of step, or implied step and end of file */
        case EndOfFileRc:
        case RotStepRc:
        case StepRc:
          if ( ! partsAdded && bfxLoad) {  // special case of no parts added, but BFX load
            if (step == NULL) {
              if (range == NULL) {
                range = newRange(steps,calledOut);
                steps->append(range);
              }
              step = new Step(topOfStep,
                              range,
                              stepNum,
                              curMeta,
                              calledOut,
                              multiStep);
              range->append(step);
            }

            int rc = step->createCsi(
              isMirrored ? addLine : "1 color 0 0 0 1 0 0 0 1 0 0 0 1 foo.ldr",
              csiParts,
              &step->csiPixmap,
              steps->meta);
            partsAdded = true; // OK, so this is a lie, but it works
          }
          if (partsAdded) {
            if (firstStep) {
              steps->stepGroupMeta = curMeta;
              firstStep = false;
            }

            if (pliIgnore) {
              parseError("PLI BEGIN then STEP. Expected PLI END",current);
              pliIgnore = false;
            }
            if (partIgnore) {
              parseError("PART BEGIN then STEP. Expected PART END",current);
              partIgnore = false;
            }
            if (synthBegin) {
              parseError("SYNTH BEGIN then STEP. Expected SYNTH_END",current);
              synthBegin = false;
            }

            bool pliPerStep;

            if (multiStep && steps->meta.LPub.multiStep.pli.perStep.value()) {
              pliPerStep = true;
            } else if (calledOut && steps->meta.LPub.callout.pli.perStep.value()) {
              pliPerStep = true;
            } else if ( ! multiStep && ! calledOut) {
              pliPerStep = true;
            } else {
              pliPerStep = false;
            }

            if (step) {
              Page *page = dynamic_cast<Page *>(steps);
              if (page) {
                page->inserts = inserts;
              }
              if (pliPerStep) {
                PlacementType relativeType;
                if (multiStep) {
                  relativeType = StepGroupType;
                } else if (calledOut) {
                  relativeType = CalloutType;
                } else {
                  relativeType = SingleStepType;
                }
                step->pli.setParts(pliParts,steps->meta);
                pliParts.clear();
                step->pli.sizePli(&steps->meta,relativeType,pliPerStep);
              }

              int rc = step->createCsi(
                 isMirrored ? addLine : "1 color 0 0 0 1 0 0 0 1 0 0 0 1 foo.ldr",
                 csiParts,
                &step->csiPixmap,
                 steps->meta);

              statusBar()->showMessage("Processing " + current.modelName);

              if (rc) {
                return rc;
              }
            } else {
              if (pliPerStep) {
                pliParts.clear();
              }
              
              /*
               * Only pages or step can have inserts.... no callouts
               */
              if ( ! multiStep && ! calledOut) {
                Page *page = dynamic_cast<Page *>(steps);
                if (page) {
                  page->inserts = inserts;
                }
              }
            }

            if ( ! multiStep && ! calledOut) {

              /*
               * Simple step
               */
              if (steps->list.size() == 0) {
                steps->relativeType = PageType;
              }
              steps->placement = steps->meta.LPub.assem.placement;
              showLine(topOfStep);

              int  numSteps = ldrawFile.numSteps(current.modelName);
              bool endOfSubmodel = numSteps == 0 || stepNum == numSteps;
              int  instances = ldrawFile.instances(current.modelName,isMirrored);

              addGraphicsPageItems(steps,coverPage,endOfSubmodel,instances,view,scene,printing);
              stepPageNum += ! coverPage;
              steps->setBottomOfSteps(current);
              return HitEndOfPage;
            }
            steps->meta.pop();
            stepNum += partsAdded;
            topOfStep = current;

            partsAdded = false;
            coverPage = false;
            step = NULL;
            bfxStore2 = bfxStore1;
            bfxStore1 = false;
            bfxLoad = false;
          }
          inserts.clear();
          steps->setBottomOfSteps(current);
        break;
        case RangeErrorRc:
          showLine(current);
          QMessageBox::critical(NULL,
                               QMessageBox::tr("LPub"),
                               QMessageBox::tr("Parameter(s) out of range: %1:%2\n%3")
                               .arg(current.modelName) 
                               .arg(current.lineNumber) 
                               .arg(line));
          return RangeErrorRc;
        break;
        default:
        break;
      }
    } else if (line != "") {
      showLine(current);
      QMessageBox::critical(NULL,
                            QMessageBox::tr("LPub"),
                            QMessageBox::tr("Invalid LDraw Line Type: %1:%2\n  %3")
                            .arg(current.modelName) 
                            .arg(current.lineNumber) 
                            .arg(line));
      return InvalidLDrawLineRc;
    }
  }
  steps->meta.rotStep.clear();
  return 0;
}
Exemple #4
0
int Gui::findPage(
  LGraphicsView  *view,
  QGraphicsScene *scene,
  int            &pageNum,
  QString const  &addLine,
  Where          &current,
  bool            isMirrored,
  Meta            meta,
  bool            printing)
{
  bool stepGroup  = false;
  bool partIgnore = false;
  bool coverPage  = false;
  bool stepPage   = false;
  bool bfxStore1  = false;
  bool bfxStore2  = false;
  QStringList bfxParts;
  int  partsAdded = 0;
  int  stepNumber = 1;
  Rc   rc;
  
  skipHeader(current);

  if (pageNum == 1) {
    topOfPages.clear();
    topOfPages.append(current);
  }

  QStringList csiParts;
  QStringList saveCsiParts;
  Where       saveCurrent = current;
  Where       stepGroupCurrent;
  int         saveStepNumber = 1;
              saveStepPageNum = stepPageNum;
              
  Meta        saveMeta = meta;

  QHash<QString, QStringList> bfx;
  QHash<QString, QStringList> saveBfx;

  int numLines = ldrawFile.size(current.modelName);

  Where topOfStep = current;
  
  ldrawFile.setRendered(current.modelName, isMirrored);

  for ( ;
       current.lineNumber < numLines;
       current.lineNumber++) {

    // scan through the rest of the model counting pages
    // if we've already hit the display page, then do as little as possible

    QString line = ldrawFile.readLine(current.modelName,current.lineNumber).trimmed();

    if (line.startsWith("0 GHOST ")) {
      line = line.mid(8).trimmed();
    }

    switch (line.toAscii()[0]) {
      case '1':
        if ( ! partIgnore) {

          csiParts << line;

          if (firstStepPageNum == -1) {
            firstStepPageNum = pageNum;
          }
          lastStepPageNum = pageNum;

          QStringList token;
          
          split(line,token);
          
          QString    type = token[token.size()-1];
          
          isMirrored = ldrawFile.mirrored(token);
          bool contains   = ldrawFile.contains(type);
          bool rendered   = ldrawFile.rendered(type,isMirrored);
                    
          if (contains) {
            if ( ! rendered && ! bfxStore2) {
              
              // can't be a callout
              SubmodelStack tos(current.modelName,current.lineNumber,stepNumber);
              meta.submodelStack << tos;
              Where current2(type,0);

              findPage(view,scene,pageNum,line,current2,isMirrored,meta,printing);
              saveStepPageNum = stepPageNum;
              meta.submodelStack.pop_back();
            }
          }
          if (bfxStore1) {
            bfxParts << token[1]+type;
          }
        }
      case '2':
      case '3':
      case '4':
      case '5':
        ++partsAdded;
        csiParts << line;
      break;

      case '0':
        rc = meta.parse(line,current);
        switch (rc) {
          case StepGroupBeginRc:
            stepGroup = true;
            stepGroupCurrent = topOfStep;
          break;
          case StepGroupEndRc:
            if (stepGroup) {
              stepGroup = false;
              if (pageNum < displayPageNum) {
                saveCsiParts   = csiParts;
                saveStepNumber = stepNumber;
                saveMeta       = meta;
                saveBfx        = bfx;
              } else if (pageNum == displayPageNum) {
                csiParts.clear();
                stepPageNum = saveStepPageNum;
                if (pageNum == 1) {
                  page.meta = meta;
                } else {
                  page.meta = saveMeta;
                }
                page.meta.pop();

                QStringList pliParts;
                
                (void) drawPage(view,
                                scene,
                                &page,
                                saveStepNumber,
                                addLine,
                                stepGroupCurrent,
                                saveCsiParts,
                                pliParts,
                                isMirrored,
                                saveBfx,
                                printing,
                                bfxStore2,
                                bfxParts);
                                
                saveCurrent.modelName.clear();
                saveCsiParts.clear();
              }
              ++pageNum;
              topOfPages.append(current);
              saveStepPageNum = ++stepPageNum;
            }
          break;

          case StepRc:
          case RotStepRc:
            if (partsAdded) {
              stepNumber += ! coverPage && ! stepPage;
              stepPageNum += ! coverPage && ! stepGroup;
              if (pageNum < displayPageNum) {
                if ( ! stepGroup) {
                  saveCsiParts   = csiParts;
                  saveStepNumber = stepNumber;
                  saveMeta       = meta;
                  saveBfx        = bfx;
                  saveStepPageNum = stepPageNum;
                }
                saveCurrent    = current;
              }
              if ( ! stepGroup) {
                if (pageNum == displayPageNum) {
                  csiParts.clear();
                  stepPageNum = saveStepPageNum;
                  if (pageNum == 1) {
                    page.meta = meta;
                  } else {
                    page.meta = saveMeta;
                  }
                  page.meta.pop();
                  QStringList pliParts;
                                    
                  (void) drawPage(view,
                                  scene,
                                  &page,
                                  saveStepNumber,
                                  addLine,
                                  saveCurrent,
                                  saveCsiParts,
                                  pliParts,
                                  isMirrored,
                                  saveBfx,
                                  printing,
                                  bfxStore2,
                                  bfxParts);

                  saveCurrent.modelName.clear();
                  saveCsiParts.clear();
                } 
                ++pageNum;
                topOfPages.append(current);
              }
              topOfStep = current;
              partsAdded = 0;
              meta.pop();
              coverPage = false;
              stepPage = false;
              bfxStore2 = bfxStore1;
              bfxStore1 = false;
              if ( ! bfxStore2) {
                bfxParts.clear();
              }
            } else if ( ! stepGroup) {
              saveCurrent = current;  // so that draw page doesn't have to
                                      // deal with steps that are not steps
            }
          break;  

          case CalloutBeginRc:
            ++current;
            {
              Meta tmpMeta;
              while (rc != CalloutEndRc && current.lineNumber < numLines) {
                line = ldrawFile.readLine(current.modelName,current.lineNumber++).trimmed();
                rc = OkRc;
                if (line[0] == '0') {
                  rc = tmpMeta.parse(line,current);
                } else if (line[0] >= '1' && line[0] <= '5') {
                  if (line[0] == '1') {
                    partsAdded++;
                    csiParts << line;
                  }
                }
              }
            }
            --current;
          break;
          
          case InsertCoverPageRc:
            coverPage  = true;
            partsAdded = true;
          break;
          case InsertPageRc:
            stepPage   = true;
            partsAdded = true;
          break;
          
          case PartBeginIgnRc:
            partIgnore = true;
          break;
          case PartEndRc:
            partIgnore = false;
          break;

          // Any of the metas that can change csiParts needs
          // to be processed here

          case ClearRc:
            csiParts.empty();
          break;

          /* Buffer exchange */
          case BufferStoreRc:
            if (pageNum < displayPageNum) {
              bfx[meta.bfx.value()] = csiParts;
            }
            bfxStore1 = true;
            bfxParts.clear();
          break;
          case BufferLoadRc:
            if (pageNum < displayPageNum) {
              csiParts = bfx[meta.bfx.value()];
            }
            partsAdded = true;
          break;

          case MLCadGroupRc:
            if (pageNum < displayPageNum) {
              csiParts << line;
              partsAdded++;
            }
          break;

          /* remove a group or all instances of a part type */
          case GroupRemoveRc:
          case RemoveGroupRc:
          case RemovePartRc:
          case RemoveNameRc:
            if (pageNum < displayPageNum) {
              QStringList newCSIParts;
              if (rc == RemoveGroupRc) {
                remove_group(csiParts,    meta.LPub.remove.group.value(),newCSIParts);
              } else if (rc == RemovePartRc) {
                remove_parttype(csiParts, meta.LPub.remove.parttype.value(),newCSIParts);
              } else {
                remove_partname(csiParts, meta.LPub.remove.partname.value(),newCSIParts);
              }
              csiParts = newCSIParts;
              newCSIParts.empty();
            }
          break;
          
          case IncludeRc:
            include(meta);
          break;
          
          default:
          break;
        } // switch
      break;
    }
  } // for every line
  csiParts.clear();
  if (partsAdded) {
    if (pageNum == displayPageNum) {
      page.meta = saveMeta;
      QStringList pliParts;
      (void) drawPage(view,
                      scene,
                      &page,
                      saveStepNumber,
                      addLine,
                      saveCurrent,
                      saveCsiParts,
                      pliParts,
                      isMirrored,
                      bfx,
                      printing,
                      bfxStore2,
                      bfxParts);
    }
    ++pageNum;
    topOfPages.append(current);
    ++stepPageNum;
  }
  return 0;
}
Exemple #5
0
int Gui::getBOMParts(
  Where           current,
  QStringList &pliParts)
{
  bool partIgnore = false;
  bool pliIgnore = false;
  bool synthBegin = false;
  bool bfxStore1 = false;
  bool bfxStore2 = false;
  bool bfxLoad = false;
  bool partsAdded = false;
  QStringList bfxParts;

  Meta meta;

  skipHeader(current);

  QHash<QString, QStringList> bfx;

  int numLines = ldrawFile.size(current.modelName);

  Rc rc;

  for ( ;
       current.lineNumber < numLines;
       current.lineNumber++) {

    // scan through the rest of the model counting pages
    // if we've already hit the display page, then do as little as possible

    QString line = ldrawFile.readLine(current.modelName,current.lineNumber).trimmed();

    if (line.startsWith("0 GHOST ")) {
      line = line.mid(8).trimmed();
    }

    switch (line.toAscii()[0]) {
      case '1':
        if ( ! partIgnore && ! pliIgnore && ! synthBegin) {

          QStringList token;

          split(line,token);

          QString    type = token[token.size()-1];

            /*
             * Automatically ignore parts added twice due to buffer exchange
             */
          bool removed = false;
          QString colorPart = token[1] + type;

          if (bfxStore2 && bfxLoad) {
            int i;
            for (i = 0; i < bfxParts.size(); i++) {
              if (bfxParts[i] == colorPart) {
                bfxParts.removeAt(i);
                removed = true;
                break;
              }
            }
          }
          if ( ! removed) {
            if (ldrawFile.contains(type)) {

              Where current2(type,0);

              getBOMParts(current2,pliParts);
            } else {

              pliParts << Pli::partLine(line,current,meta);
            }
          }
          if (bfxStore1) {
            bfxParts << colorPart;
          }
          partsAdded = true;
        }
      break;
      case '0':
        rc = meta.parse(line,current);

        /* substitute part/parts with this */

        switch (rc) {
          case PliBeginSub1Rc:
            if (! pliIgnore &&
                ! partIgnore &&
                ! synthBegin) {

              QString line = QString("1 0  0 0 0  0 0 0  0 0 0  0 0 0 %1") .arg(meta.LPub.pli.begin.sub.value().part);
              pliParts << Pli::partLine(line,current,meta);
              pliIgnore = true;
            }
          break;

          /* substitute part/parts with this */
          case PliBeginSub2Rc:
            if (! pliIgnore &&
                ! partIgnore &&
                ! synthBegin) {
              QString line = QString("1 %1  0 0 0  0 0 0  0 0 0  0 0 0 %2")
                .arg(meta.LPub.pli.begin.sub.value().color)
                .arg(meta.LPub.pli.begin.sub.value().part);
              pliParts << Pli::partLine(line,current,meta);
              pliIgnore = true;
            }
          break;

          case PliBeginIgnRc:
            pliIgnore = true;
          break;

          case PliEndRc:
            pliIgnore = false;
          break;

          case PartBeginIgnRc:
            partIgnore = true;
          break;

          case PartEndRc:
            partIgnore = false;
          break;

          case SynthBeginRc:
            synthBegin = true;
          break;

          case SynthEndRc:
            synthBegin = false;
          break;

          /* Buffer exchange */
          case BufferStoreRc:
            bfxStore1 = true;
            bfxParts.clear();
          break;
          case BufferLoadRc:
            bfxLoad = true;
          break;


          // Any of the metas that can change pliParts needs
          // to be processed here

          case ClearRc:
            pliParts.empty();
          break;

          case MLCadGroupRc:
            pliParts << Pli::partLine(line,current,meta);
          break;

          /* remove a group or all instances of a part type */
          case GroupRemoveRc:
          case RemoveGroupRc:
          case RemovePartRc:
          case RemoveNameRc:
            {
              QStringList newCSIParts;
              if (rc == RemoveGroupRc) {
                remove_group(pliParts,meta.LPub.remove.group.value(),newCSIParts);
              } else if (rc == RemovePartRc) {
                remove_parttype(pliParts, meta.LPub.remove.parttype.value(),newCSIParts);
              } else {
                remove_partname(pliParts, meta.LPub.remove.partname.value(),newCSIParts);
              }
              pliParts = newCSIParts;
            }
          break;

          case StepRc:
            if (partsAdded) {
              bfxStore2 = bfxStore1;
              bfxStore1 = false;
              bfxLoad = false;
              if ( ! bfxStore2) {
                bfxParts.clear();
              }
            }
            partsAdded = false;
          break;

          default:
          break;
        } // switch
      break;
    }
  } // for every line
  return 0;
}