static void SetupGraph(void)
{
  if (Event == EV_FUNC_FIRST)
  {
    LcdBlank(); /* Clear screen */
    MenuPos = 0;
    IntervalCorrection = 0;
    EncCounter = TimeInterval - 1;
    goto redraw;
  }
  if ( (Event& EV_MASK) == EV_KEY_PRESSED )
  {
    switch (Event & KEY_MASK)
    {
      case KEY_UP:
        if (IntervalCorrection == 0)
        {
          MenuPos++;
          if ( MenuPos > 2 )
            MenuPos = 0;
          goto redraw;
        }
      case KEY_DOWN:
        if (IntervalCorrection == 0)
        {
          if ( MenuPos == 0 )
            MenuPos = 2;
          else
            MenuPos--;
          goto redraw;
        }
        TimeInterval = EncCounter + 1;
        goto redraw;

      case KEY_ENTER:
        switch (MenuPos)
        {
          case 1: /* Clear */
            ClearGraph();
          case 0: /* Return */
            CurrentFunc(DisplayGraph);
            return;
          default: /* Interval */
            if ( IntervalCorrection == 0)
              IntervalCorrection = 1;
            else
            {
              IntervalCorrection = 0;
            }
        }
    }
  }      
  return;

redraw:  
  LcdChr(14+1*Y_POSITION+0*X_POSITION + (MenuPos==0?INVERSE:0), "Return");
  LcdChr(14+2*Y_POSITION+0*X_POSITION + (MenuPos==1?INVERSE:0), "Clear");
  LcdChr(14+3*Y_POSITION+0*X_POSITION + (MenuPos==2?INVERSE:0), "Interval");
  OutValueSmall(3, 9, TimeInterval*2, 3, MenuPos==2?1:0);
}
Exemple #2
0
	void DemoKeeper::notifyMenuCtrlAccept(wraps::ContextMenu* _sender, const std::string& _id)
	{
		if (_id == "SaveGraph")
		{
			SaveGraph();
			return;
		}
		else if (_id == "LoadGraph")
		{
			LoadGraph();
			return;
		}
		else if (_id == "ClearGraph")
		{
			ClearGraph();
			return;
		}

		std::string name = _id;
		size_t index = name.find("Controller");
		if (index != MyGUI::ITEM_NONE) name.erase(index);
		else
		{
			index = name.find("State");
			if (index != MyGUI::ITEM_NONE) name.erase(index);
		}

		static size_t name_index = 0;
		name_index++;
		name = MyGUI::utility::toString(name, "_", name_index);

		createNode(_id, name);
	}
Exemple #3
0
	void DemoKeeper::notifyEndDialog(common::OpenSaveFileDialog* _sender, bool _result)
	{
		mFileDialog->setVisible(false);
		if (!_result) return;

		if (mFileDialogSave)
		{
			std::string filename = mFileDialog->getFileName();
			size_t index = filename.find_first_of('.');
			if (index == std::string::npos)
				filename += ".xml";
			filename = mFileDialog->getCurrentFolder() + "/" + filename;

			saveToFile(filename);
		}
		else
		{
			ClearGraph();

			std::string filename = mFileDialog->getFileName();
			filename = mFileDialog->getCurrentFolder() + "/" + filename;

			loadFromFile(filename);
		}
	}
IdentifyLiaisonTunnel::~IdentifyLiaisonTunnel( void )
{
    if( bInitNetwokState )
    {
        ClearGraph( dg, datas );
    }
}
Exemple #5
0
/* simulate an LF Manchester encoded tag with specified bitstream, clock rate and inter-id gap */
int CmdLFSimManchester(const char *Cmd)
{
  static int clock, gap;
  static char data[1024], gapstring[8];

  /* get settings/bits */
  sscanf(Cmd, "%i %s %i", &clock, &data[0], &gap);

  /* clear our graph */
  ClearGraph(0);

  /* fill it with our bitstream */
  for (int i = 0; i < strlen(data) ; ++i)
    AppendGraph(0, clock, data[i]- '0');

  /* modulate */
  CmdManchesterMod("");

  /* show what we've done */
  RepaintGraphWindow();

  /* simulate */
  sprintf(&gapstring[0], "%i", gap);
  CmdLFSim(gapstring);
  return 0;
}
	void DemoKeeper::notifyEndDialog(tools::Dialog* _dialog, bool _result)
	{
		if (_result)
		{
			if (mFileDialogSave)
			{
				std::string filename = mFileDialog->getFileName();
				size_t index = filename.find_first_of('.');
				if (index == std::string::npos)
					filename += ".xml";
				filename = mFileDialog->getCurrentFolder() + "/" + filename;

				saveToFile(filename);
			}
			else
			{
				ClearGraph();

				std::string filename = mFileDialog->getFileName();
				filename = mFileDialog->getCurrentFolder() + "/" + filename;

				loadFromFile(filename);
			}
		}

		_dialog->endModal();
	}
Exemple #7
0
void clGraph::From2DGrid( const LVector3& Center, const LVector3& V1, const LVector3& V2, float SizeX, float SizeY, int Nx, int Ny, int Conn )
{
	ClearGraph();

	LVector3 N = V1.Cross( V2 );

	// common orientation for all nodes
	LQuaternion Orientation;
	Orientation.FromAxisAngle( N, 0.0f );

	float CellX = SizeX / Nx;
	float CellY = SizeY / Ny;

	FOriented = false;

	FLocalOrientations.resize( Nx * Ny );
	FVertices.resize( Nx * Ny );

	for ( int i = 0 ; i < Nx ; i++ )
	{
		for ( int j = 0 ; j < Ny ; j++ )
		{
			int ThisNode = NodeForPair( i, j, Nx, Ny );

			FLocalOrientations[ThisNode] = Orientation;

			FVertices[ThisNode] = Center + V1 * static_cast<float>( i - Nx / 2 ) * CellX + V2 * static_cast<float>( j - Ny / 2 ) * CellY;

			// add 4-connected edges
			int West  = NodeForPair( i - 1, j, Nx, Ny );
			int East  = NodeForPair( i + 1, j, Nx, Ny );
			int North = NodeForPair( i, j - 1, Nx, Ny );
			int South = NodeForPair( i, j - 1, Nx, Ny );

			if ( West > -1 )  { FEdge0.push_back( ThisNode ); FEdge1.push_back( West );  }

			if ( East > -1 )  { FEdge0.push_back( ThisNode ); FEdge1.push_back( East );  }

			if ( North > -1 ) { FEdge0.push_back( ThisNode ); FEdge1.push_back( North ); }

			if ( South > -1 ) { FEdge0.push_back( ThisNode ); FEdge1.push_back( South ); }

			if ( Conn > 4 )
			{
				int NW = NodeForPair( i - 1, j - 1, Nx, Ny );
				int NE = NodeForPair( i + 1, j - 1, Nx, Ny );
				int SW = NodeForPair( i - 1, j + 1, Nx, Ny );
				int SE = NodeForPair( i + 1, j + 1, Nx, Ny );

				if ( NW > -1 ) { FEdge0.push_back( ThisNode ); FEdge1.push_back( NW ); }

				if ( NE > -1 ) { FEdge0.push_back( ThisNode ); FEdge1.push_back( NE ); }

				if ( SW > -1 ) { FEdge0.push_back( ThisNode ); FEdge1.push_back( SW ); }

				if ( SE > -1 ) { FEdge0.push_back( ThisNode ); FEdge1.push_back( SE ); }
			}
		}
	}
}
FindWindStation::~FindWindStation( void )
{
    if( bInitNetwokState )
    {
        // 不需要更新数据
//		UpdateData(dg, datas);
        ClearGraph( dg, datas );
    }
}
FindWindStation::FindWindStation( void ) : datas( dg ), ef( dg, true ), bInitNetwokState( true )
{
    // 初始化网络以及添加处理源汇
    if( !initNetwok() )
    {
        ClearGraph( dg, datas );
        setInitNetwokState( false );
    }
    else
    {
        initAirEdges();   // 记录用风地点分支
    }
}
Exemple #10
0
TGraph* TrPdf::CreateGraph() {	
  if (Graph!=0) ClearGraph();
  float* x = new float[N];
  float* y = new float[N];
  for (int i=0; i<N; i++) {
    x[i] = X.at(i);
    y[i] = Y.at(i);
  }
  Graph = new TGraph(N,x,y);
  delete [] x;
  delete [] y;
  return Graph;
}
IdentifyLiaisonTunnel::IdentifyLiaisonTunnel( void ) : datas( dg ), ef( dg, true ), bInitNetwokState( true )
{
    // 初始化网络以及添加处理源汇
    if( !initNetwok() )
    {
        ClearGraph( dg, datas );
        setInitNetwokState( false );
    }
    else
    {
        // 初始化用风分支
        initAirEdges();
    }
}
Exemple #12
0
void CPlanarGraph::RandomInitGraph()
{
	ClearGraph();

	int minSkeletonSize = 5;
	int additionalSkeletonSize = Random2(5);
	int mainSkeletonSize = minSkeletonSize + additionalSkeletonSize;
	AddGraphNodes(mainSkeletonSize);

	// Add blue key branch: don't let this happen in the main room
	int blueLoop = Random2(minSkeletonSize-1) + 1;

	// add red key branch: don't let this happen in the main room
	int redLoop = Random2(minSkeletonSize-1) + 1;

	int blueSectionLength = 4 + Random2(4);
	int redSectionLength = 4 + Random2(4);

	if ( blueLoop < mainSkeletonSize )
	{
		AddGraphNodes(blueSectionLength, blueLoop);
		if ( CoinFlip() )
		{
			int idx0 = GetNumOfNodes() - 1;
			int idx1 = Random2(minSkeletonSize);
			AddGraphEdge(CGraphEdge(idx0, idx1));
		}
	}

	if ( redLoop < mainSkeletonSize )
	{
		AddGraphNodes(redSectionLength, redLoop);
		if ( CoinFlip() )
		{
			int idx0 = GetNumOfNodes() - 1;
			int idx1 = Random2(minSkeletonSize);
			AddGraphEdge(CGraphEdge(idx0, idx1));
		}
	}

	// Add decoration
	int numStubs = Random2(5);
	for ( int i=0; i<numStubs; i++ )
	{
		int offset = Random2(mainSkeletonSize);
		AddGraphNodes(1+Random2(2), offset);
	}
}
Exemple #13
0
bool CPlanarGraph::LoadGraphFromXML(const char* fileName, bool flagDetectFaces /* = true */, bool flagIgnoreIndiv /* = true */)
{
	// Clear the current graph...
	ClearGraph();

	TiXmlDocument doc;
	bool loadFlag = doc.LoadFile(fileName);
	if ( loadFlag == false )
	{
		std::cout << "Failed to load graph from " << fileName << "!\n";
		return loadFlag;
	}
	//doc.Print();

	TiXmlNode* xmlRoot = 0;
	xmlRoot = doc.RootElement();
	assert( xmlRoot );

	TiXmlNode* xmlNode = xmlRoot->FirstChild();
	while ( xmlNode != 0 )
	{
		if ( strcmp(xmlNode->Value(), "Node") == 0 )
		{
			// Parse a node...
			CGraphNode graphNode;
			float px, py;
			int rx = xmlNode->ToElement()->QueryFloatAttribute("px", &px);
			int ry = xmlNode->ToElement()->QueryFloatAttribute("py", &py);
			if ( rx != TIXML_SUCCESS || ry != TIXML_SUCCESS )
			{
				graphNode.RandomlyInitPos();
			}
			else
			{
				graphNode.SetPos(px, py);
			}
			int type;
			int r = xmlNode->ToElement()->QueryIntAttribute("type", &type);
			if ( r == TIXML_SUCCESS )
			{
				graphNode.SetType(type);
			}
			int boundary;
			int rb = xmlNode->ToElement()->QueryIntAttribute("boundary", &boundary);
			if ( rb == TIXML_SUCCESS )
			{
				graphNode.SetBoundaryType(boundary);
			}
			int fixed;
			int rf = xmlNode->ToElement()->QueryIntAttribute("fix", &fixed);
			if ( rf == TIXML_SUCCESS && fixed != 0 )
			{
				graphNode.SetFlagFixed(true);
			}
			const char* str = xmlNode->ToElement()->Attribute("name");
			if ( *str != '\0' )
			{
				graphNode.SetName(str);
			}
			AddGraphNode(graphNode);
		}
		else if ( strcmp(xmlNode->Value(), "Edge") == 0 )
		{
			// Parse an edge...
			int idx0 = -1;
			int idx1 = -1;
			int r0 = xmlNode->ToElement()->QueryIntAttribute("node0", &idx0);
			int r1 = xmlNode->ToElement()->QueryIntAttribute("node1", &idx1);
			if ( r0 != TIXML_SUCCESS )
			{
				const char* str = xmlNode->ToElement()->Attribute("name0");
				idx0 = FindNodeAccordingToName(str);
			}
			if ( r1 != TIXML_SUCCESS )
			{
				const char* str = xmlNode->ToElement()->Attribute("name1");
				idx1 = FindNodeAccordingToName(str);
			}
			if ( idx0 >= 0 && idx1 >= 0 )
			{
				CGraphEdge graphEdge(idx0, idx1);
				AddGraphEdge(graphEdge);
			}
		}

		// Move to the next sibling...
		xmlNode = xmlNode->NextSibling();
	}

	SetNodeNeighbors();
	if ( flagIgnoreIndiv == true )
	{
		RemoveIndividualNodes();
	}
	if ( flagDetectFaces == false )
	{
		return loadFlag;
	}
	//PrintGraph();

	// Step 1: Detect faces of the planar graph...
	DetectFaces();
	return loadFlag;
}
CPacketFilterGraph::~CPacketFilterGraph()
{
  ClearGraph();
}