Exemplo n.º 1
0
Standard_Boolean GeomImportExport::Read(const QString& aFileName,
                                        TopoDS_Shape& aShape)
{
	Standard_Boolean result;
	
	if (aFileName.endsWith (".brep", Qt::CaseInsensitive))
	{
		result = ReadBREP (aFileName, aShape);
	}else
	if (aFileName.endsWith (".step", Qt::CaseInsensitive) || aFileName.endsWith (".stp", Qt::CaseInsensitive) )
	{
		result = ReadSTEP (aFileName, aShape);
	}else
	if (aFileName.endsWith (".igs", Qt::CaseInsensitive) || aFileName.endsWith (".iges", Qt::CaseInsensitive) )
	{
		result = ReadIGES (aFileName, aShape);
	}else
	{
		result = ReadBREP (aFileName, aShape);
	}
	
	
    return result;
}
Exemplo n.º 2
0
static gboolean
expose (GtkWidget *da, GdkEventExpose *event, gpointer user_data)
{
	GdkGLContext *glcontext = gtk_widget_get_gl_context (da);
	GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (da);

	// g_print (" :: expose\n");

	if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext))
	{
		g_assert_not_reached ();
	}

	/* draw in here */
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	//glDepthFunc(GL_GREATER);  // The Type Of Depth Testing (Less Or Equal)
    glEnable(GL_DEPTH_TEST);  
    
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, material_diffuse);
    
         
	glPushMatrix();

	glRotatef (ang, 1, 0, 1);
	// glRotatef (ang, 0, 1, 0);
	// glRotatef (ang, 0, 0, 1);

	glShadeModel(GL_SMOOTH);
	glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	

/*
	glBegin (GL_LINES);
	glColor3f (1., 0., 0.);
	glVertex3f (0., 0., 0.);
	glVertex3f (1., 0., 0.);
	glEnd ();

	glBegin (GL_LINES);
	glColor3f (0., 1., 0.);
	glVertex3f (0., 0., 0.);
	glVertex3f (0., 1., 0.);
	glEnd ();

	glBegin (GL_LINES);
	glColor3f (0., 0., 1.);
	glVertex3f (0., 0., 0.);
	glVertex3f (0., 0., 1.);
	glEnd (); */

	FreeREP::Init();

    Geom_Vec3 pt1(0,0,0);
    Geom_Vec3 pt2(0,1,0);
    Geom_Vec3 pt3(1,1,0);
    Geom_Vec3 pt4(1,0,0);

    Geom_Vec3 pt5(0.5,0.5,0);
    Geom_Vec3 pt6(0.5,.75,0);
    Geom_Vec3 pt7(.75,.75,0);


    Topo_Line *l1 = new Topo_Line(pt1,pt2);
    Topo_Line *l2 = new Topo_Line(pt2,pt3);
    Topo_Line *l3 = new Topo_Line(pt3,pt4);

    Topo_Arc *a1 = new Topo_Arc(Geom_Ax2(pt4,Geom_Vec3(0,0,-1),Geom_Vec3(-1,0,0)),1,M_PI/2,0);

    Topo_Line *l4 = new Topo_Line(pt5,pt6);
    Topo_Line *l5 = new Topo_Line(pt6,pt7);
    Topo_Line *l6 = new Topo_Line(pt7,pt5);

/*
    Topo_Edge *e1 = new Topo_Edge();
    e1->Add(l1);
    e1->Add(l2);
    //e1->Add(l3);
    e1->Add(a1);
    e1->Reverse();

    Topo_Edge *e2 = new Topo_Edge();
    e2->Add(l4);
    e2->Add(l5);
    e2->Add(l6);
*/
/*
    glBegin(GL_LINE_STRIP);
    e1->GetVertices(.01,vCall);
    glEnd();

    glBegin(GL_LINE_STRIP);
    e2->GetVertices(.01,vCall);
    glEnd(); */

/*
    Topo_Face *face = new Topo_Face_Planar(Geom_Plane(Geom_Vec3(0,0,0),Geom_Vec3(0,0,-1)));
    face->Add(e1);
    face->Add(e2);*/

    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    glEnable(GL_AUTO_NORMAL);
    
    //Draw a coordinate axis on the screen
    glBegin(GL_LINES);
    
    glVertex3d(0,0,0);
    glVertex3d(0,0,.5);
    
    glVertex3d(0,0,0);
    glVertex3d(0,.5,0);
    
    glVertex3d(0,0,0);
    glVertex3d(.5,0,0);
    
    glEnd();
    
    glPushMatrix();
    glScaled(.25,.25,.25);
    
    glPushMatrix();
    glTranslated(-.5,.5,0);
    t3dDraw3D("Y", 0, 0, 0.05f);
	glPopMatrix();

	glPushMatrix();
    glTranslated(.5,-.5,0); 
    glRotated(90,0,0,1);
    t3dDraw3D("X", 0, 0, 0.05f);
	glPopMatrix();
	
	glTranslated(-.5,0,0.5); 
    glRotated(90,1,0,0);
    t3dDraw3D("Z", 0, 0, 0.05f);
	
	
	glPopMatrix();

    glBegin(GL_TRIANGLES);
    //face->Triangulate(.01,vCall);
    glEnd();
    
    Topo_Face_Spheric *sphere = new Topo_Face_Spheric(Geom_Ax2(Geom_Vec3(0,0,0),Geom_Vec3(0,0,1),Geom_Vec3(1,0,0)),1);
    glBegin(GL_TRIANGLES);
    //sphere->Triangulate(.01,vCall);
    glEnd();
    
    Topo_Face_Toroidal *toroid = new Topo_Face_Toroidal(Geom_Ax2(Geom_Vec3(0,0,0),Geom_Vec3(0,0,1),Geom_Vec3(1,0,0)),.5,.125);
    glBegin(GL_TRIANGLES);
    //toroid->Triangulate(.01,vCall);
    glEnd();

    //Topo_Solid *solid = BrepAlgoExtrude(face,Geom_Vec3(0,0,.5));

    glBegin(GL_TRIANGLES); 
    //solid->Triangulate(.001,vCall); 
    glEnd(); 
    
    std::vector<Topo_Shape*> shapes = ReadIGES("Tests/Pawn.igs");// = ReadFREP("Tests/SimpleFaces.FREP");
    
//    shapes.push_back(MakeSphere(Geom_Ax2(Geom_Vec3(0,0,0),Geom_Vec3(0,0,1),Geom_Vec3(1,0,0)),1));
//    shapes.push_back(MakeSphere(Geom_Ax2(Geom_Vec3(0,0,0),Geom_Vec3(0,0,1),Geom_Vec3(1,0,0)),0.25));
//    shapes.push_back(MakeCone(Geom_Ax2(Geom_Vec3(0,0,0),Geom_Vec3(0,0,1),Geom_Vec3(1,0,0)),.5,1,1));
    
    for(int i=0; i < shapes.size(); i++)
    {
    	ICanTriangulate *obj = dynamic_cast<ICanTriangulate*>(shapes[i]);
    	if(obj)
    	{
 #ifdef DRAWFACES
    		glBegin(GL_TRIANGLES);
    		obj->Triangulate(.01,vCall);
    		glEnd();
 #endif
 #ifdef DRAWEDGES
    		Topo_Face *face = dynamic_cast<Topo_Face*>(shapes[i]);
    		if(face)
    		{
    			Topo_Edge* edge = face->GetFirstEdge();
    			while(edge)
    			{
	    			glBegin(GL_LINE_STRIP);
    				edge->GetVertices(.01,dvCall);
    				glEnd();	
    				
    				edge = face->GetNextEdge();	
    			}	
    		}

    		Topo_Solid *solid = dynamic_cast<Topo_Solid*>(shapes[i]);
    		if(solid)
    		{
    			face = solid->GetFirstFace();
    			while(face)
    			{
    				Topo_Edge* edge = face->GetFirstEdge();
    				while(edge)
    				{
		    			glBegin(GL_LINE_STRIP);
    					edge->GetVertices(.01,dvCall);
    					glEnd();	
    				
    					edge = face->GetNextEdge();	
    				}
    				face = solid->GetNextFace();
    			}	
    		}
    	
 #endif
    	}
    	else
    	{
    		Topo_Edge *edge = dynamic_cast<Topo_Edge*>(shapes[i]);
    		if(edge)
    		{
    			glBegin(GL_LINE_STRIP);
    			edge->GetVertices(.01,dvCall);
    			glEnd();	
    		}
    		
    		Topo_Wire *wire = dynamic_cast<Topo_Wire*>(shapes[i]);
    		if(wire)
    		{
    			glBegin(GL_LINE_STRIP);
    			wire->GetVertices(.01,dvCall);
    			glEnd();	
    		}	
    			
    	}
    }
    
/*    Topo_Face *tface = solid->GetFirstFace();
    while(tface)
    {
        Topo_Edge *tedge = tface->GetFirstEdge();
        while(tedge)
        {
            glBegin(GL_LINE_STRIP);
            tedge->GetVertices(.01,vCall);
            glEnd();

            tedge = tface->GetNextEdge();
        }

        tface = solid->GetNextFace();
    }*/


	glPopMatrix ();

	if (gdk_gl_drawable_is_double_buffered (gldrawable))
		gdk_gl_drawable_swap_buffers (gldrawable);

	else
		glFlush ();

	gdk_gl_drawable_gl_end (gldrawable);

	return TRUE;
}