예제 #1
0
 void main()
 {
   int i,j,k,n;
   VertexType v1,v2;
   MGraph g;
   CreateFAG(&g);
   Display(g);
   printf("修改顶点的值,请输入原值 新值: ");
   scanf("%s%s",v1,v2);
   PutVex(&g,v1,v2);
   printf("深度优先搜索的结果:\n");
   DFSTraverse(g,visit);
   printf("广度优先搜索的结果:\n");
   BFSTraverse(g,visit);
   printf("删除一条边或弧,请输入待删除边或弧的弧尾 弧头:");
   scanf("%s%s",v1,v2);
   DeleteArc(&g,v1,v2);
   Display(g);
   DestroyGraph(&g);
   printf("请顺序选择有向图,有向网,无向图,无向网\n");
   for(i=0;i<4;i++) /* 验证4种情况 */
   {
     CreateGraph(&g);
     Display(g);
     printf("插入新顶点,请输入顶点的值: ");
     scanf("%s",v1);
     InsertVex(&g,v1);
     printf("插入与新顶点有关的弧或边,请输入弧或边数: ");
     scanf("%d",&n);
     for(k=0;k<n;k++)
     {
       printf("请输入另一顶点的值: ");
       scanf("%s",v2);
       if(g.kind<=1) /* 有向 */
       {
         printf("对于有向图或网,请输入另一顶点的方向(0:弧头 1:弧尾): ");
         scanf("%d",&j);
         if(j)
           InsertArc(&g,v2,v1);
         else
           InsertArc(&g,v1,v2);
       }
       else /* 无向 */
         InsertArc(&g,v1,v2);
     }
     Display(g);
     printf("删除顶点及相关的弧或边,请输入顶点的值: ");
     scanf("%s",v1);
     DeleteVex(&g,v1);
     Display(g);
     DestroyGraph(&g);
   }
 }
예제 #2
0
void main()
{
	GraphLnk gl;
	InitGraph(&gl);
	InsertVertex(&gl,'A');
	InsertVertex(&gl,'B');
	InsertVertex(&gl,'C');
	InsertVertex(&gl,'D');
	InsertVertex(&gl,'E');

	InsertEdge(&gl,'A','B');
	InsertEdge(&gl,'A','D');
	InsertEdge(&gl,'B','C');
	InsertEdge(&gl,'B','E');
	InsertEdge(&gl,'C','D');
	InsertEdge(&gl,'C','E');
	ShowGraph(&gl);

	//RemoveEdge(&gl,'A','C');
	//RemoveVertex(&gl,'C');
	ShowGraph(&gl);

	//int v = GetFirstNeighbor(&gl,'A');
	int v = GetNextNeighbor(&gl,'B','A');

	DestroyGraph(&gl);
}
예제 #3
0
 void main()
 {
   int k,n;
   AMLGraph g;
   VertexType v1,v2;
   CreateGraph(&g);
   Display(g);
   printf("修改顶点的值,请输入原值 新值: ");
   scanf("%s%s",v1,v2);
   PutVex(&g,v1,v2);
   printf("插入新顶点,请输入顶点的值: ");
   scanf("%s",v1);
   InsertVex(&g,v1);
   printf("插入与新顶点有关的边,请输入边数: ");
   scanf("%d",&n);
   for(k=0;k<n;k++)
   {
     printf("请输入另一顶点的值: ");
     scanf("%s",v2);
     InsertArc(&g,v1,v2);
   }
   Display(g);
   printf("深度优先搜索的结果:\n");
   DFSTraverse(g,visit);
   printf("广度优先搜索的结果:\n");
   BFSTraverse(g,visit);
   DestroyGraph(&g);
 }
예제 #4
0
Graph copyGraph(Graph D, Graph S)
{
    if(S->vertex != D->vertex)
    {
        DestroyGraph(D);
        D = intializeGraph(S->vertex);
    }

    /*必须先对每一个顶点赋值,因为图的顶点排列是通过
    开放定址法的哈希表,插入顺序不同会导致顶点的序号不同*/
    copyVertex(D, S);

    VertexType vertex1, vertex2;
    WeightType weight;
    for(int i=0; i<S->vertex; i++)
    {
        strcpy(vertex1, S->TheCells[i].vertexName);
        Edge edge = S->TheCells[i].next;
        while(edge != NULL)
        {
            weight = edge->weight;
            strcpy(vertex2, S->TheCells[edge->vertexIndex].vertexName);
            insertEdge(vertex1, vertex2, weight, D);
            edge = edge ->next;
        }
    }
    return D;
}
예제 #5
0
int main( int argc, char** argv )
{
   graphSize_t source, target;
   graph_t* graph;
   clock_t start, end;
   
   if ( argc != 3 )
   {
      printf( "Syntax: <executable> <source node ID> <target node ID>\n" );
      exit( 1 );
   }
   source = atoi( argv[ 2 ] );
   target = atoi( argv[ 1 ] );

   start = clock();
   graph = CreateGraphEELab();
   SetRoverPosition( graph, 84, 120 );
   UpdateNodeVisibilityAndDistances( graph );
   
   printf( "%d inches of travel\n", Dijkstra( graph, source, target ) ); 

   end = clock();
   printf( "It took %d clock cycles.\n", end - start );
   DestroyGraph( graph ); 

   return 0;
}
예제 #6
0
void
DestroySimGraph(ClientData clientData)
{
  SimGraph *graph = (SimGraph *) clientData;

  DestroyGraph(graph);
}
예제 #7
0
void PathingGraph::BuildTestGraph(void)
{
	// this should never occur, but better safe than sorry
	if (!m_nodes.empty())
		DestroyGraph();
	
	// keep from reallocating and copying the array
	m_nodes.reserve(81);

	// Create a simple grid of nodes.  Using these hard-coded values is a bit hacky but it's okay 
	// because this is just a debug function.
	int index = 0;  // this is used to keep track of the node we just inserted so we can link it to adjacent nodes
	for (float x = -45.0f; x < 45.0f; x += 10.0f)
	{
		for (float z = -45.0f; z < 45.0f; z += 10.0f)
		{
			// add the new node
			PathingNode* pNode = new PathingNode(Vec3(x,0,z));
			m_nodes.push_back(pNode);
			
			// link it to the previous node
			int tempNode = index - 1;
			if (tempNode >= 0)
				LinkNodes(m_nodes[tempNode],pNode);
				
			// link it to the node above it
			tempNode = index - 9;  // reusing tempNode
			if (tempNode >= 0)
				LinkNodes(m_nodes[tempNode],pNode);
				
			index++;
		}
	}
}
예제 #8
0
파일: DShow.cpp 프로젝트: GWARDAR/OpenPLi-1
HRESULT CloseInterface(HWND hwnd)
{
    HRESULT hr=NOERROR;
    RELEASE(gpVCap);
    DestroyGraph(gpIGraphBuilder);
    RELEASE(gpICaptureGraphBuilder);
    RELEASE(gpIGraphBuilder);
    return(hr);
}
예제 #9
0
void main(){
	MGraph N;
	printf("创建一个网:\n");
	CreateGraph(&N);
	printf("输出网的顶点和弧:\n");
	DisplayGraph(N);
	printf("销毁网:\n");
	DestroyGraph(&N);
	system("pause");
}
예제 #10
0
파일: cbc.c 프로젝트: rafaelalmeida/poc
Region *ComputeRegions(CImage *cimg, Image *mask)
{
  Region *r=NULL;
  Graph *g;

  g = CreateGraph(cimg);
  r = MakeRegions(g, mask);
  DestroyGraph(&g);

  return(r);
}
예제 #11
0
파일: DShow.cpp 프로젝트: GWARDAR/OpenPLi-1
HRESULT RebuildGraph()
{
    HRESULT hr=NOERROR;
    hr=DestroyGraph(gpIGraphBuilder);
    if (FAILED(hr))
        return(hr);
    hr=AddCaptureFilterToGraph(gpIGraphBuilder, gpVCap, gszCaptureFilterName);
    if (FAILED(hr))
        return(hr);
    return(hr);
}
예제 #12
0
파일: x11.c 프로젝트: aesop972/ngspice-gss
void
killwin(Widget w, caddr_t client_data, caddr_t call_data)
{

    GRAPH *graph = (GRAPH *) client_data;

    /* Iplots are done asynchronously */
    DEVDEP(graph).isopen = 0;
    /* MW. Not sure but DestroyGraph might free() to much - try Xt...() first */	
    XtDestroyWidget(DEVDEP(graph).shell);
    DestroyGraph(graph->graphid);

}
예제 #13
0
 void main()
 {
   ALGraph g;
   CreateGraphF(g); // 利用数据文件创建无向图,在bo7-2.cpp中
   Display(g); // 输出无向图,在bo7-2.cpp中
   printf("深度优先搜索的结果:\n");
   DFSTraverse(g,visit); // 调用算法7.4,在bo7-2.cpp中
   DFSTraverse1(g,visit); // 另一种方法,在bo7-2.cpp中
   printf("广度优先搜索的结果:\n");
   BFSTraverse(g,visit); // 调用算法7.6,在bo7-2.cpp中
   BFSTraverse1(g,visit); // 另一种方法,在bo7-2.cpp中
   DestroyGraph(g); // 销毁图g
 }
예제 #14
0
파일: VideoPlay.cpp 프로젝트: niepp/sperm-x
void CMyVideoPlay::CreateGraph()
{
	DestroyGraph();
	m_FilterGraph = new CDXGraph(m_strSourceFile, m_hDisplayWnd);
	if (m_FilterGraph->Create())
	{
		// Render the source clip
		m_FilterGraph->DisplayVideoWin();
		// Set video window and notification window
		m_FilterGraph->SetDisplayWindow(m_hDisplayWnd);
		m_FilterGraph->SetNotifyWindow(m_hNotifyWnd);
		// Show the first frame
		m_FilterGraph->Pause();
	}
}
예제 #15
0
 void main()
 {
   int i,j,k,n;
   ALGraph g;
   VertexType v1,v2;
   printf("请顺序选择有向图,有向网,无向图,无向网\n");
   for(i=0;i<4;i++) // 验证4种情况
   {
     CreateGraph(g);
     Display(g);
     printf("插入新顶点,请输入顶点的值: ");
     scanf("%s",v1);
     InsertVex(g,v1);
     printf("插入与新顶点有关的弧或边,请输入弧或边数: ");
     scanf("%d",&n);
     for(k=0;k<n;k++)
     {
       printf("请输入另一顶点的值: ");
       scanf("%s",v2);
       if(g.kind<=1) // 有向
       {
	 printf("对于有向图或网,请输入另一顶点的方向(0:弧头 1:弧尾): ");
	 scanf("%d",&j);
	 if(j)
	   InsertArc(g,v2,v1);
	 else
	   InsertArc(g,v1,v2);
       }
       else // 无向
	 InsertArc(g,v1,v2);
     }
     Display(g);
     if(i==3)
     {
       printf("删除一条边或弧,请输入待删除边或弧的弧尾 弧头:");
       scanf("%s%s",v1,v2);
       DeleteArc(g,v1,v2);
       printf("修改顶点的值,请输入原值 新值: ");
       scanf("%s%s",v1,v2);
       PutVex(g,v1,v2);
     }
     printf("删除顶点及相关的弧或边,请输入顶点的值: ");
     scanf("%s",v1);
     DeleteVex(g,v1);
     Display(g);
     DestroyGraph(g);
   }
 }
예제 #16
0
파일: graf.c 프로젝트: imr/ngspice
void
gr_end_iplot(void)
{
    struct dbcomm *db, *prev, *next;
    GRAPH *graph;
    struct dveclist *link;
    struct dvec *dv;

    prev = NULL;
    for (db = dbs; db; prev = db, db = next) {
        next = db->db_next;
        if (db->db_type == DB_DEADIPLOT) {
            if (db->db_graphid) {
                DestroyGraph(db->db_graphid);
                if (prev)
                    prev->db_next = next;
                else
                    ft_curckt->ci_dbs = dbs = next;
                dbfree1(db);
            }
        } else if (db->db_type == DB_IPLOT || db->db_type == DB_IPLOTALL) {
            if (db->db_graphid) {

                /* get private copy of dvecs */
                graph = FindGraph(db->db_graphid);

                link = graph->plotdata;

                while (link) {
                    dv = link->vector;
                    link->vector = vec_copy(dv);
                    /* vec_copy doesn't set v_color or v_linestyle */
                    link->vector->v_color = dv->v_color;
                    link->vector->v_linestyle = dv->v_linestyle;
                    link->vector->v_flags |= VF_PERMANENT;
                    link = link->next;
                }

                db->db_graphid = 0;
            } else {
                /* warn that this wasn't plotted */
                fprintf(cp_err, "Warning: iplot %d was not executed.\n",
                        db->db_number);
            }
        }
    }
}
예제 #17
0
파일: Test_Graph.c 프로젝트: hss440/algo1
int main( void )
{
    /*  그래프 생성     */
    Graph* G = CreateGraph();
    
    /*  정점 생성 */
    Vertex* V1 = CreateVertex( '1' );
    Vertex* V2 = CreateVertex( '2' );
    Vertex* V3 = CreateVertex( '3' );
    Vertex* V4 = CreateVertex( '4' );
    Vertex* V5 = CreateVertex( '5' );

    /*  그래프에 정점을 추가 */
    AddVertex( G, V1 );
    AddVertex( G, V2 );
    AddVertex( G, V3 );
    AddVertex( G, V4 );
    AddVertex( G, V5 );

    /*  정점과 정점을 간선으로 잇기 */
    AddEdge( V1, CreateEdge(V1, V2, 0) );
    AddEdge( V1, CreateEdge(V1, V3, 0) );
    AddEdge( V1, CreateEdge(V1, V4, 0) );
    AddEdge( V1, CreateEdge(V1, V5, 0) );

    AddEdge( V2, CreateEdge(V2, V1, 0) );
    AddEdge( V2, CreateEdge(V2, V3, 0) );
    AddEdge( V2, CreateEdge(V2, V5, 0) );

    AddEdge( V3, CreateEdge(V3, V1, 0) );
    AddEdge( V3, CreateEdge(V3, V2, 0) );

    AddEdge( V4, CreateEdge(V4, V1, 0) );
    AddEdge( V4, CreateEdge(V4, V5, 0) );

    AddEdge( V5, CreateEdge(V5, V1, 0) );
    AddEdge( V5, CreateEdge(V5, V2, 0) );
    AddEdge( V5, CreateEdge(V5, V4, 0) );

    PrintGraph( G );

    /*  그래프 소멸 */
    DestroyGraph( G );

    return 0;
}
예제 #18
0
int main()
{
	//그래프 생성
	Graph* G = CreateGraph();

	// 정점 생성
	Vertex* V1 = CreateVertex('1');
	Vertex* V2 = CreateVertex('2');
	Vertex* V3 = CreateVertex('3');
	Vertex* V4 = CreateVertex('4');
	Vertex* V5 = CreateVertex('5');

	// 그래프에 정점을 추가
	AddVertex(G, V1);
	AddVertex(G, V2);
	AddVertex(G, V3);
	AddVertex(G, V4);
	AddVertex(G, V5);

	// 정점과 정점을 간선으로 잇기
	AddEdge(V1, CreateEdge(V1, V2, 0));
	AddEdge(V1, CreateEdge(V1, V3, 0));
	AddEdge(V1, CreateEdge(V1, V4, 0));
	AddEdge(V1, CreateEdge(V1, V5, 0));

	AddEdge(V2, CreateEdge(V2, V1, 0));
	AddEdge(V2, CreateEdge(V2, V2, 0));
	AddEdge(V2, CreateEdge(V2, V5, 0));

	AddEdge(V3, CreateEdge(V3, V1, 0));
	AddEdge(V3, CreateEdge(V3, V2, 0));

	AddEdge(V4, CreateEdge(V4, V1, 0));
	AddEdge(V4, CreateEdge(V4, V5, 0));

	AddEdge(V5, CreateEdge(V5, V1, 0));
	AddEdge(V5, CreateEdge(V5, V2, 0));
	AddEdge(V5, CreateEdge(V5, V4, 0));

	PrintGraph(G);

	// 그래프 소멸
	DestroyGraph(G);

	return 0;
}
예제 #19
0
파일: x11.c 프로젝트: amarnathmhn/ngspice
/* called from postcoms.c
   In the command 'destroy ac2' Will remove window associated with
   the plot (e.g. ac2) just before data of the plot are deleted.*/
void
RemoveWindow(GRAPH *graph)
{
    if (graph->devdep) {
        /* Iplots are done asynchronously */
        DEVDEP(graph).isopen = 0;
        /* MW. Not sure but DestroyGraph might free() to much - try Xt...() first */
        XtUnmapWidget(DEVDEP(graph).shell);
        XtDestroyWidget(DEVDEP(graph).shell);
        XFreeFont(display, DEVDEP(graph).font);
        XFreeGC(display, DEVDEP(graph).gc);
    }

    if (graph == currentgraph)
        currentgraph = NULL;

    DestroyGraph(graph->graphid);
}
예제 #20
0
/* called by SystemMenue / Print */
LRESULT PrintPlot( HWND hwnd)
{
   GRAPH * graph;
   GRAPH * temp;

   /* get pointer to graph */
   graph = pGraph( hwnd);
   if (!graph) return 0;

   /* switch to printer */
   /* (results in WPRINT_Init()) */
   if (DevSwitch("WinPrint")) return 0;

   /* Cursor = wait */
   SetCursor( LoadCursor( NULL, IDC_WAIT));

   /* copy graph */
   temp = CopyGraph(graph);
   if (!temp) goto PrintEND;

   /* add to the copy the new printer data */
   if (NewViewport(temp)) goto PrintEND2;

   /* make correction to placement of grid (copy from gr_init) */
   temp->viewportxoff = temp->fontwidth  * 8;
   temp->viewportyoff = temp->fontheight * 4;

   /* print the graph */
   gr_resize(temp);

PrintEND2:
   /* delete temporary graph */
   DestroyGraph(temp->graphid);

PrintEND:
   /* switch back to screen */
   DevSwitch(NULL);

   /* Cursor = normal */
   SetCursor( LoadCursor( NULL, IDC_ARROW));

   return 0;
}
예제 #21
0
Graph maxStream(VertexType source, VertexType sink, Graph G)
{
    Index S = findVertex(source, G);
    Index E = findVertex(sink, G);
    if(G->TheCells[S].Info != Legitimate || G->TheCells[E].Info != Legitimate)
    {
        fprintf(stderr, "vertex %s or %s does not exist", source, sink);
        return NULL;
    }
    /*准备好残余图和流图*/
    Graph Gr = intializeGraph(G->vertex);
    Gr = copyGraph(Gr, G);
    Graph Gf = intializeGraph(G->vertex);
    copyVertex(Gf, G);


    maxStream(S, E, Gf, Gr);
    DestroyGraph(Gr);

    return Gf;
}
예제 #22
0
파일: hpgl.c 프로젝트: Anastien/ngspice
int
GL_Close(void)
{
    /* in case GL_Close is called as part of an abort,
       w/o having reached GL_NewViewport */
    if (plotfile) {
        if (DEVDEP(currentgraph).lastlinestyle != -1) {
            DEVDEP(currentgraph).linecount = 0;
        }
        fclose(plotfile);
        plotfile = NULL;
    }
    /* In case of hardcopy command destroy the hardcopy graph
     * and reset currentgraph to graphid 1, if possible
     */
    if (!screenflag) {
        DestroyGraph(hcopygraphid);
        currentgraph = FindGraph(1);
    }

    return 0;
}
예제 #23
0
 void main()
 {
   int j,k,n;
   OLGraph g;
   VertexType v1,v2;
   CreateDG(g);
   Display(g);
   printf("修改顶点的值,请输入原值 新值: ");
   scanf("%s%s",v1,v2);
   PutVex(g,v1,v2);
   printf("插入新顶点,请输入顶点的值: ");
   scanf("%s",v1);
   InsertVex(g,v1);
   printf("插入与新顶点有关的弧,请输入弧数: ");
   scanf("%d",&n);
   for(k=0;k<n;k++)
   {
     printf("请输入另一顶点的值 另一顶点的方向(0:弧头 1:弧尾): ");
     scanf("%s%d",v2,&j);
     if(j)
       InsertArc(g,v2,v1);
     else
       InsertArc(g,v1,v2);
   }
   Display(g);
   printf("删除一条弧,请输入待删除弧的弧尾 弧头:");
   scanf("%s%s",v1,v2);
   DeleteArc(g,v1,v2);
   Display(g);
   printf("删除顶点及相关的弧,请输入顶点的值: ");
   scanf("%s",v1);
   DeleteVex(g,v1);
   Display(g);
   printf("深度优先搜索的结果:\n");
   DFSTraverse(g,visit);
   printf("广度优先搜索的结果:\n");
   BFSTraverse(g,visit);
   DestroyGraph(g);
 }
예제 #24
0
 void main()
 {
   int i,j,k,n;
   MGraph g;
   VertexType v1,v2;
   printf("请顺序选择有向图,有向网,无向图,无向网\n");
   for(i=0;i<4;i++) // 验证4种情况
   {
     CreateGraph(g); // 构造图g
     Display(g); // 输出图g
     printf("插入新顶点,请输入顶点的值: ");
     scanf("%s",v1);
     InsertVex(g,v1);
     printf("插入与新顶点有关的弧或边,请输入弧或边数: ");
     scanf("%d",&n);
     for(k=0;k<n;k++)
     {
       printf("请输入另一顶点的值: ");
       scanf("%s",v2);
       if(g.kind<=1) // 有向
       {
         printf("对于有向图或网,请输入另一顶点的方向(0:弧头 1:弧尾): ");
         scanf("%d",&j);
         if(j) // v2是弧尾
           InsertArc(g,v2,v1);
         else // v2是弧头
           InsertArc(g,v1,v2);
       }
       else // 无向
         InsertArc(g,v1,v2);
     }
     Display(g); // 输出图g
     printf("删除顶点及相关的弧或边,请输入顶点的值: ");
     scanf("%s",v1);
     DeleteVex(g,v1);
     Display(g); // 输出图g
   }
   DestroyGraph(g); // 销毁图g
 }
예제 #25
0
/* window procedure */
LRESULT CALLBACK PlotWindowProc( HWND hwnd,
   UINT uMsg, WPARAM wParam, LPARAM lParam)
{
   static int x0,y0,xep,yep;
   int xe, ye, prevmix;
   static double fx0,fy0;
   double fxe, fye;
   double angle;
   char buf[BSIZE_SP];
   char buf2[128];
   char *t;
   HDC hdc;
   HPEN OldPen;
   HPEN NewPen;   
   
   switch (uMsg) {
   case WM_SYSCOMMAND:
   {
      /* test command */
      int cmd = wParam & ID_MASK;
      switch(cmd) {
         case ID_DRUCKEN:  return PrintPlot( hwnd);
         case ID_DRUCKEINR:      return PrintInit( hwnd);
         case ID_HARDCOPY: return HcpyPlot( hwnd);
         case ID_HARDCOPY_BW: return HcpyPlotBW( hwnd);
      }
   }
   goto WIN_DEFAULT;

   case WM_LBUTTONDOWN:
   {
      GRAPH * gr = pGraph( hwnd);                      
      xep = x0 = LOWORD (lParam);
      yep = y0 = HIWORD (lParam);
      /* generate x,y data from grid coordinates */
      WIN_ScreentoData(gr, x0, y0, &fx0, &fy0);
   } 
   goto WIN_DEFAULT;  
   
   case WM_MOUSEMOVE:
      /* left mouse button: connect coordinate pair by dashed pair of x, y lines */
      if (wParam & MK_LBUTTON)
      {
          hdc = GetDC (hwnd) ;
          if (isblack)
             prevmix = SetROP2(hdc, R2_XORPEN);
          else
             prevmix = SetROP2(hdc, R2_NOTXORPEN);
          /* Create white dashed pen */
          NewPen = CreatePen( LType(12), 0, ColorTable[1] );
          OldPen = SelectObject(hdc, NewPen);
          /* draw lines with previous coodinates -> delete old line because of XOR */
          MoveToEx (hdc, x0, y0, NULL) ;
          LineTo   (hdc, x0, yep) ;
          LineTo   (hdc, xep, yep);
          /* get new end point */
          xe = LOWORD (lParam);
          ye = HIWORD (lParam);
          /* draw new lines */
          MoveToEx (hdc, x0, y0, NULL) ;
          LineTo   (hdc, x0, ye) ;
          LineTo   (hdc, xe, ye);
          /* restore standard color mix */
          SetROP2(hdc, prevmix);
          OldPen = SelectObject(hdc, OldPen);
          DeleteObject( NewPen);    
          ReleaseDC (hwnd, hdc) ;
          /* restore new to previous coordinates */
          yep = ye;
          xep = xe;
      }
      /* right mouse button: create white (black) dashed box */
      else if (wParam & MK_RBUTTON){
         hdc = GetDC (hwnd) ;
         if (isblack)
            prevmix = SetROP2(hdc, R2_XORPEN);
         else
            prevmix = SetROP2(hdc, R2_NOTXORPEN);
         /* Create white (black) dashed pen */
         NewPen = CreatePen( LType(12), 0, ColorTable[1] );
         OldPen = SelectObject(hdc, NewPen);
         /* draw box with previous coodinates -> delete old lines because of XOR */
         MoveToEx (hdc, x0, y0, NULL) ;
         LineTo   (hdc, x0, yep) ;
         LineTo   (hdc, xep, yep);
         LineTo   (hdc, xep, y0) ;
         LineTo   (hdc, x0, y0);
         /* get new end point */
         xe = LOWORD (lParam);
         ye = HIWORD (lParam);
         /* draw new box */
         MoveToEx (hdc, x0, y0, NULL) ;
         LineTo   (hdc, x0, ye) ;
         LineTo   (hdc, xe, ye);
         LineTo   (hdc, xe, y0) ;
         LineTo   (hdc, x0, y0);
         /* restore standard color mix */
         SetROP2(hdc, prevmix);
         OldPen = SelectObject(hdc, OldPen);
         DeleteObject( NewPen);    
         ReleaseDC (hwnd, hdc) ;
         /* restore new to previous coordinates */
         yep = ye;
         xep = xe;
      }
   goto WIN_DEFAULT;
           
   /* get final coordinates upon left mouse up */
   /* calculate and print out the data */
   case WM_LBUTTONUP:
   {
      GRAPH * gr = pGraph( hwnd);  
      InvalidateRect (hwnd, NULL, TRUE) ;
      xe = LOWORD (lParam);
      ye = HIWORD (lParam);
      WIN_ScreentoData(gr, xe, ye, &fxe, &fye);

      /* print it out */
      if (xe == x0 && ye == y0) {     /* only one location */
         fprintf(stdout, "\nx0 = %g, y0 = %g\n", fx0, fy0);
         if (gr->grid.gridtype == GRID_POLAR
         || gr->grid.gridtype == GRID_SMITH
         || gr->grid.gridtype == GRID_SMITHGRID)
         {
            angle = RAD_TO_DEG * atan2( fy0, fx0 );
            fprintf(stdout, "r0 = %g, a0 = %g\n",
            sqrt( fx0*fx0 + fy0*fy0 ),
            (angle>0)?angle:(double) 360+angle);
         }
      } else  {    
         /* need to print info about two points */
         fprintf(stdout, "\nx0 = %g, y0 = %g    x1 = %g, y1 = %g\n",
            fx0, fy0, fxe, fye);
         fprintf(stdout, "dx = %g, dy = %g\n", fxe-fx0, fye - fy0);
         if (xe != x0 && ye != y0) {
         /* add slope info if both dx and dy are zero, */
         /* because otherwise either dy/dx or dx/dy is zero, */
         /* which is uninteresting */
   
         fprintf(stdout, "dy/dx = %g    dx/dy = %g\n",
            (fye-fy0)/(fxe-fx0), (fxe-fx0)/(fye-fy0));
         }
      }
      SetFocus( swString);
   } 
   goto WIN_DEFAULT;
           
   /* get starting coordinates upon right mouse button down */
   case WM_RBUTTONDOWN:
   {
      GRAPH * gr = pGraph( hwnd);                      
      x0 = xep = LOWORD (lParam);
      y0 = yep = HIWORD (lParam);
      WIN_ScreentoData(gr, x0, y0, &fx0, &fy0);
   } 
   goto WIN_DEFAULT;  
   /* get final coordinates upon right mouse button up */
   /* copy xlimit, ylimit command into buf */
   /* start plot loop with argument buf   */
   case WM_RBUTTONUP:
   {
      GRAPH * gr = pGraph( hwnd);
      InvalidateRect (hwnd, NULL, TRUE) ;
      xe = LOWORD (lParam);
      ye = HIWORD (lParam);
      /* do nothing if mouse curser is not moved in both x and y */
      if ((xe == x0) || (ye == y0)) {
         SetFocus( swString);
         goto WIN_DEFAULT;
      }  
      WIN_ScreentoData(gr, xe, ye, &fxe, &fye);
      
      strncpy(buf2, gr->plotname, sizeof(buf2));
      if ((t = index(buf2, ':'))) /* strchr */
         *t = 0;

      if (!eq(plot_cur->pl_typename, buf2)) {
         (void) sprintf(buf,
//       "setplot %s; %s xlimit %e %e ylimit %e %e; setplot $curplot\n",
         "setplot %s; %s xlimit %e %e ylimit %e %e\n",
         buf2, gr->commandline, fx0, fxe, fy0, fye);
      } else {
         (void) sprintf(buf, "%s xlimit %e %e ylimit %e %e\n",
         gr->commandline, fx0, fxe, fy0, fye);
      }

      (void) cp_evloop(buf);
      SetFocus( swString);
   }
   goto WIN_DEFAULT;

   case WM_CLOSE: /* close window */
   {
      GRAPH * g = pGraph( hwnd);

      if (g) {
         /* if g equals currentgraph, set a new currentgraph. 
            Otherwise gr_resize(g) might fail. */
         if (g == currentgraph)
            currentgraph = FindGraph(g->graphid - 1);
         DestroyGraph(g->graphid);
      }
   }
   goto WIN_DEFAULT;

   case WM_PAINT: /* replot window (e.g. after Resize) */
      {
         PAINTSTRUCT ps;
         GRAPH * g;
         tpWindowData wd;
         HDC saveDC;    /* the DC from BeginPaint is different... */
         HDC newDC;

         /* has to happen */
         newDC = BeginPaint( hwnd, &ps);
         g = pGraph( hwnd);
         if (g) {
            wd = pWindowData(g);
            if (wd) {
               if (!wd->PaintFlag && !wd->FirstFlag) {
                  /* avoid recursive call */
                  wd->PaintFlag = 1;
                  /* get window sizes */
                  GetClientRect( hwnd, &(wd->Area));
                  g->absolute.width  = wd->Area.right;
                  g->absolute.height = wd->Area.bottom;
                  /* switch DC */
                  saveDC = wd->hDC;
                  wd->hDC = newDC;
//                currentgraph = g;
                  
                  /* plot anew */
                  gr_resize(g);
                  /* switch DC */
                  wd->hDC = saveDC;
                  /* ready */
                  wd->PaintFlag = 0;
               }
             }
         }
         /* finish */
         EndPaint( hwnd, &ps);
      }
      return 0;

   default:
WIN_DEFAULT:
      return DefWindowProc( hwnd, uMsg, wParam, lParam);
   }
}
예제 #26
0
파일: VideoPlay.cpp 프로젝트: niepp/sperm-x
CMyVideoPlay::~CMyVideoPlay()
{
	DestroyGraph();
}
예제 #27
-1
void main(){
	MGraph N;
	printf("创建一个无向网:\n");
	CreateGraph(&N);
	DisplayGraph(N);
	Prim(N,"A");	
	DestroyGraph(&N);
	system("pause");
}