Esempio n. 1
0
void EnviroGUI::SetState(AppState s)
{
	// if entering or leaving terrain or orbit state
	AppState previous = m_state;
	m_state = s;

	if (m_state != previous)
	{
		VTLOG("Changing app state from %s to %s\n", AppStateNames[previous],
			AppStateNames[m_state]);
		GetFrame()->SetTitle(wxGetApp().MakeFrameTitle(GetCurrentTerrain()));
	}

	if ((previous == AS_Terrain && m_state != AS_Terrain) ||
		(previous == AS_Orbit && m_state != AS_Orbit) ||
		(previous != AS_Terrain && m_state == AS_Terrain) ||
		(previous != AS_Orbit && m_state == AS_Orbit))
	{
		GetFrame()->RefreshToolbar();
	}

	if (s == AS_Error)
	{
		// If we encounter an error while trying to open a terrain, don't get
		//  stuck in a progress dialog.
		CloseProgressDialog2();
	}
}
Esempio n. 2
0
bool EnviroGUI::SaveStructures(bool bAskFilename)
{
	VTLOG1("EnviroGUI::SaveStructures\n");

	vtStructureLayer *st_layer = GetCurrentTerrain()->GetStructureLayer();
	vtString fname = st_layer->GetFilename();
	if (bAskFilename)
	{
		// save current directory
		wxString path = wxGetCwd();

		wxString default_file(StartOfFilename(fname), wxConvUTF8);
		wxString default_dir(ExtractPath(fname, false), wxConvUTF8);

		EnableContinuousRendering(false);
		wxFileDialog saveFile(NULL, _("Save Built Structures Data"),
			default_dir, default_file, FSTRING_VTST,
			wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
		bool bResult = (saveFile.ShowModal() == wxID_OK);
		EnableContinuousRendering(true);
		if (!bResult)
		{
			wxSetWorkingDirectory(path);	// restore
			return false;
		}
		wxString str = saveFile.GetPath();
		fname = str.mb_str(wxConvUTF8);
		st_layer->SetFilename(fname);
	}
	bool success = false;
	try {
		success = st_layer->WriteXML(fname);
	}
	catch (xh_io_exception &e)
	{
		string str = e.getFormattedMessage();
		VTLOG("  Error: %s\n", str.c_str());
		wxMessageBox(wxString(str.c_str(), wxConvUTF8), _("Error"));
	}
	if (success)
		st_layer->SetModified(false);
	return success;
}
Esempio n. 3
0
bool EnviroGUI::SaveVegetation(bool bAskFilename)
{
	VTLOG1("EnviroGUI::SaveVegetation\n");

	vtTerrain *pTerr = GetCurrentTerrain();
	vtVegLayer *vlay = pTerr->GetVegLayer();

	if (!vlay)
		return false;

	vtString fname = vlay->GetFilename();

	if (bAskFilename)
	{
		// save current directory
		wxString path = wxGetCwd();

		wxString default_file(StartOfFilename(fname), wxConvUTF8);
		wxString default_dir(ExtractPath(fname, false), wxConvUTF8);

		EnableContinuousRendering(false);
		wxFileDialog saveFile(NULL, _("Save Vegetation Data"), default_dir,
			default_file, FSTRING_VF, wxFD_SAVE);
		bool bResult = (saveFile.ShowModal() == wxID_OK);
		EnableContinuousRendering(true);
		if (!bResult)
		{
			wxSetWorkingDirectory(path);	// restore
			return false;
		}
		wxString str = saveFile.GetPath();
		fname = str.mb_str(wxConvUTF8);
		vlay->SetFilename(fname);
	}
	bool success = vlay->WriteVF(fname);
	if (success)
		vlay->SetModified(false);
	return true;
}
Esempio n. 4
0
//
// Test code
//
void EnviroFrame::DoTestCode()
{
	SetMode(MM_SLOPE);

#if 0
	// Shadow tests
	const int ReceivesShadowTraversalMask = 0x1;
	const int CastsShadowTraversalMask = 0x2;

	osg::ref_ptr<osgShadow::ShadowedScene> shadowedScene = new osgShadow::ShadowedScene;

	shadowedScene->setReceivesShadowTraversalMask(ReceivesShadowTraversalMask);
	shadowedScene->setCastsShadowTraversalMask(CastsShadowTraversalMask);

#if 0
	osg::ref_ptr<osgShadow::ShadowMap> sm = new osgShadow::ShadowMap;
	shadowedScene->setShadowTechnique(sm.get());
	int mapres = 1024;
	sm->setTextureSize(osg::Vec2s(mapres,mapres));
#else
	osg::ref_ptr<osgShadow::ShadowTexture> sm = new osgShadow::ShadowTexture;
	shadowedScene->setShadowTechnique(sm.get());
#endif

	osg::Group* cessna1 = (osg::Group*) osgDB::readNodeFile("cessna.osg");
	if (!cessna1)
		return;
	cessna1->setNodeMask(CastsShadowTraversalMask);
	cessna1->getChild(0)->setNodeMask(CastsShadowTraversalMask);

	osg::Group* cessna2 = (osg::Group*) osgDB::readNodeFile("cessna.osg");
	if (!cessna2)
		return;
	int flags_off = ~(CastsShadowTraversalMask | ReceivesShadowTraversalMask);
	cessna2->setNodeMask(flags_off);
	cessna2->getChild(0)->setNodeMask(flags_off);

	osg::MatrixTransform* positioned = new osg::MatrixTransform;
	positioned->setDataVariance(osg::Object::STATIC);
	positioned->setMatrix(osg::Matrix::rotate(osg::inDegrees(-90.0f),0.0f,1.0f,0.0f)
		*osg::Matrix::translate(40,40,0));
	positioned->addChild(cessna1);

//osg::ref_ptr<osg::Group> shadowedScene = new osg::Group;
	shadowedScene->addChild(positioned);
	shadowedScene->addChild(cessna2);

	//	osg::ref_ptr<osg::Group> container = new osg::Group;
	//	container->addChild(positioned);
	//    container->addChild(cessna2);

	vtGroup *vtg = GetCurrentTerrain()->GetTerrainGroup();
	vtg->GetOsgGroup()->addChild(shadowedScene.get());
	//	vtg->GetOsgGroup()->addChild(container.get());

	vtLogGraph(shadowedScene.get());
#endif
#if 0
	if (pTerr && g_App.m_bSelectedStruct)
	{
		vtStructureArray3d *sa = pTerr->GetStructureLayer();
		int i = 0;
		while (!sa->GetAt(i)->IsSelected())
			i++;
		vtBuilding3d *bld = sa->GetBuilding(i);
		// (Do something to the building as a test)
		sa->ConstructStructure(bld);
	}
#endif
#if 0
	{
		// Read points from a text file, create OBJ file with geometry at that locations
		FILE *fp = fopen("test.txt", "r");
		if (!fp) return;

		char buf[80];
		float depth, x, y;

		// Add the geometry and materials to the shape
		vtGeode *pGeode = new vtGeode;
		vtMaterialArray *pMats = new vtMaterialArray;
		pMats->AddRGBMaterial(RGBf(1.0f, 1.0f, 1.0f), false, false, false);
		pGeode->SetMaterials(pMats);

		vtMesh *mesh = new vtMesh(osg::PrimitiveSet::TRIANGLES, VT_Normals | VT_Colors, 4000);

		int line = 0;
		fgets(buf, 80, fp);	// skip first
		while (fgets(buf, 80, fp) != NULL)
		{
			sscanf(buf, "%f\t%f\t%f", &depth, &x, &y);
			int idx = mesh->NumVertices();
			for (int i = 0; i < 20; i++)
			{
				double angle = (double)i / 20.0 * PI2d;
				FPoint3 vec;
				vec.x = x/2 * cos(angle);
				vec.y = 0.0f;
				vec.z = y/2 * sin(angle);

				// normal
				FPoint3 norm = vec;
				norm.Normalize();

				// color
				RGBAf col(1.0f, 1.0f, 1.0f, 1.0f);
				if (x > y)
				{
					float frac = (x-y)/1.5f;	// typical: 0 - 1.2
					col.g -= frac;
					col.b -= frac;
				}
				else if (y > x)
				{
					float frac = (y-x)/1.5f;	// typical: 0 - 1.2
					col.r -= frac;
					col.g -= frac;
				}

				int add = mesh->AddVertexN(vec.x, /*650*/-depth, vec.z,
					norm.x, norm.y, norm.z);
				mesh->SetVtxColor(add, col);
			}
			if (line != 0)
			{
				for (int i = 0; i < 20; i++)
				{
					int next = (i+1)%20;
					mesh->AddTri(idx-20 + i, idx + i,    idx-20 + next);
					mesh->AddTri(idx    + i, idx + next, idx-20 + next);
				}
			}
			line++;
		}
		pGeode->AddMesh(mesh, 0);
		WriteGeomToOBJ(pGeode, "bore.obj");

		vtTransform *model = new vtTransform;
		model->addChild(pGeode);
		DPoint3 pos;
		g_App.m_pTerrainPicker->GetCurrentEarthPos(pos);
		GetCurrentTerrain()->AddNode(model);
		GetCurrentTerrain()->PlantModelAtPoint(model, DPoint2(pos.x, pos.y));
	}
#endif
}
Esempio n. 5
0
void UtilityVisitor::startElement(const char *name, const XMLAttributes &atts)
{
	const char *attval;

	// clear data at the start of each element
	m_data = "";

	if (m_state == 0)
	{
		if (!strcmp(name, "UtilityCollection"))
		{
			m_state = 1;
		}
		else
		{
			string message = "Root element name is ";
			message += name;
			message += "; expected UtilityCollection";
			throw xh_io_exception(message, "XML Reader");
		}
		return;
	}
	if (m_state == 1)
	{
		if (!strcmp(name, "OverheadLine"))
		{
			m_pRoute = new vtRoute(GetCurrentTerrain());		// Create new route (should this be in vtUtilityMap ??)
			attval = atts.getValue("name");
			if (attval)
				m_pRoute->SetName(attval);		// TODO Set Name of the overhead line
			GetCurrentTerrain()->AddRoute(m_pRoute);
			m_state = 2;
		}
		return;
	}

	if (m_state == 2)	// Conductor
	{
		if (!strcmp(name, "Conductor"))
		{
			attval = atts.getValue("width");
			if (attval)
				m_pRoute->SetThickness(atof(attval));
			attval = atts.getValue("color");
			if (attval)
				m_pRoute->SetColor(ParseHexColor(attval));
			m_state = 3;
		}
		return;
	}

	if (m_state == 3)	// Pylon
	{
		if (!strcmp(name, "Pylon"))
		{
			attval = atts.getValue("name");
			if (attval)
				SetName(attval);
			attval = atts.getValue("reference");
			if (attval)
				SetReference(attval);
			attval = atts.getValue("rotation");
			if (attval)
				SetRotation(atof(attval));

			m_state = 4;	// now read in the coordinate ...
		}
		else
			m_state = 1;	// then it is a new overhead line
		return;
	}
}