示例#1
0
vector< Geom* > GeomScreen::s_get_geom(deque< Stringc > selectVec)
{
	vector< Geom * > geomVec;
	for (int i = 0; i < (int)selectVec.size(); i++)
	{	// select geoms
		Stringc name = selectVec[i];
		name.trim('\"');
		vector<Geom *> gVec;

		if (name.get_length() > 0 && name[0] == '+')
		{	// + indicates children selection
			name.remove_leading('+');
			gVec = aircraftPtr->getGeomByName(name, 1);
		}
		else
		{
			gVec = aircraftPtr->getGeomByName(name, 0);
		}

		for (int j = 0; j < (int)gVec.size(); j++)
		{	// add all geoms that are not already in the list
			vector< Geom* >::iterator giter = find(geomVec.begin(), geomVec.end(), gVec[j]);
			if (giter == geomVec.end())
				geomVec.push_back(gVec[j]);
		}
	}
	return geomVec;
}
示例#2
0
void GroupScreen::screenCB( Fl_Widget* w )
{
	if ( w == groupUI->acceptScaleButton )
	{
		scriptMgr->addLineDouble("xform scale", geomGroup->scaleFactor());
		geomGroup->acceptScaleFactor();
	}
	else if ( w == groupUI->acceptXformButton )
	{
		scriptMgr->addLine("xform", "loc", geomGroup->xLocOff(), geomGroup->yLocOff(), geomGroup->zLocOff());
		scriptMgr->addLine("xform", "rot", geomGroup->xRotOff(), geomGroup->yRotOff(), geomGroup->zRotOff());

		geomGroup->acceptXform();
	}
	else if ( w == groupUI->resetScaleButton )
	{
		geomGroup->resetScaleFactor();
		scriptMgr->addLine("xform", "resetscale");
	}
	else if ( w == groupUI->resetXformButton )
	{
		geomGroup->resetXform();		
		scriptMgr->addLine("xform", "resetxform");
	}
	else if ( w == groupUI->redSlider || 
			  w == groupUI->greenSlider	||
			  w == groupUI->blueSlider )				
	{
		int r = (int)groupUI->redSlider->value();
		int g = (int)groupUI->greenSlider->value();
		int b = (int)groupUI->blueSlider->value();

		geomGroup->setColor( r, g, b );

		groupUI->primColorButton->color( fl_rgb_color(r, g, b) );
		groupUI->primColorButton->redraw();

		if (!Fl::event_state(FL_BUTTONS))
			scriptMgr->addLine("gen", "color", r, g, b);
	}
	else if ( w == groupUI->materialChoice )
	{
		geomGroup->setMaterialID( groupUI->materialChoice->value() );
		Stringc matName = matMgrPtr->getMaterial(groupUI->materialChoice->value())->name();
		matName.quote('\"');
//		char str[128];
//		sprintf(str, "\"%s\"", matMgrPtr->getMaterial(groupUI->materialChoice->value())->name());
		scriptMgr->addLine("gen", "material", matName);
	}
	else if ( w == groupUI->scaleLocButton )
	{
		geomGroup->setScaleLocFlag( groupUI->scaleLocButton->value() );
	}



}
示例#3
0
void autoSaveTimeoutHandler(void *data)
{
	if ( airPtr )
	{
		Stringc backupfn = airPtr->getTempDir();
		backupfn.concatenate("vsp_autobackup.vsp"); 
		airPtr->writeFile(backupfn.get_char_star(), true);
	}

	Fl::repeat_timeout(VspPreferences::Instance()->autoSaveInterval, autoSaveTimeoutHandler, data );
}
示例#4
0
void autoSaveTimeoutHandler(void *data)
{
	if ( airPtr )
	{
		Stringc backupfn = airPtr->getTempDir();
		backupfn.concatenate("vsp_autobackup.vsp"); 
		airPtr->writeFile(backupfn.get_char_star());
	}

	Fl::repeat_timeout(AUTO_SAVE_TIME, autoSaveTimeoutHandler, data );
}
示例#5
0
vec2d TextLabel::drawString(GLFont * glfont, float scale, Stringc str, float x0, float y0, float xoffset, float yoffset) 
{

	double w = 0; 
	double h = 0;
	if (str.get_length() > 0) {

		//alignment 
		pair< int, int > dimension;
		glfont->GetStringSize(str.get_char_star(), &dimension);
		w = ((float) dimension.first) * FONT_BASE_SCALE * scale;		
		h = ((float) dimension.second) * FONT_BASE_SCALE * scale;
		double x = x0 - w/2  + w*xoffset;
		double y = y0 + h/2 + h*yoffset;

		glfont->Begin();
		glfont->DrawString(str.get_char_star(), (float)(FONT_BASE_SCALE * scale), (float)x, (float)y);
	}
	return vec2d(w,h);
}
示例#6
0
void GeomScreen::loadGeomBrowser()
{
	int i;

	//==== Save List of Selected Geoms ====//
	vector< Geom* > selVec = getSelectedGeomVec();

	lastTopLine = geomUI->geomBrowser->topline();

	//==== Get Geoms To Display ====//
	vector< Geom* > geomVec = aircraftPtr->getDisplayGeomVec();
//	vector< Geom* > geomVec = aircraftPtr->getGeomVec();

	geomUI->geomBrowser->clear();
	geomUI->geomBrowser->add( aircraftPtr->getName() );

	for ( i = 0 ; i < (int)geomVec.size() ; i++ )
	{
		Stringc str; 
		//==== Check if Parent is Selected ====//
		if ( isParentSelected( geomVec[i], selVec ) )
			str.concatenate("@b@.");

		int numindents = geomVec[i]->countParents(0);
		for ( int j = 0 ; j < numindents ; j++ )
		{
			str.concatenate("--");
		}
		if ( geomVec[i]->getPosAttachFlag() == POS_ATTACH_NONE )
			str.concatenate("> ");
		else
			str.concatenate("^ ");

		if ( !geomVec[i]->getDisplayChildrenFlag() )
			str.concatenate("(+) ");

		str.concatenate(geomVec[i]->getName()); 

		if ( geomVec[i]->getNoShowFlag() )
			str.concatenate("(no show)");

		geomUI->geomBrowser->add( str );
	}

	//==== Restore List of Selected Geoms ====//
	for ( i = 0 ; i < (int)selVec.size() ; i++ )
		selectGeomBrowser( selVec[i] );


}
示例#7
0
void SelectFileScreen::screenCB( Fl_Widget* w )
{
	if ( w == selectFileUI->fileBrowser )
	{
		int sid = selectFileUI->fileBrowser->value();
		selectFileUI->fileBrowser->select( sid );

		Stringc selText = Stringc(selectFileUI->fileBrowser->text(sid));

		if ( selText == "../" )
		{
			if ( m_DirString.count_substrings( "/" ) > 1 )
			{
				int dirLen = m_DirString.get_length();
				int slashLoc = dirLen-2;

				while ( slashLoc > 0 )
				{
					if ( m_DirString[slashLoc] == '/' )
						break;
					slashLoc--;
				}
				if ( slashLoc+1 <= dirLen-1 )
					m_DirString.delete_range( slashLoc+1, dirLen-1 );

				selectFileUI->fileBrowser->load( m_DirString.get_char_star() );
				selectFileUI->dirInput->value( m_DirString );
			}
		}
		else if ( selText.count_substrings( "/" ) >= 1 )
		{
			m_DirString.concatenate( selText );
			selectFileUI->fileBrowser->load( m_DirString.get_char_star() );
			selectFileUI->dirInput->value( m_DirString );	
		}
		else
		{
			m_FileName = selText;
			selectFileUI->fileInput->value( m_FileName );
		}
	}
	else if ( w == selectFileUI->dirInput )
	{
		m_DirString = Stringc(selectFileUI->dirInput->value());

		char forwardSlash = '\\';
		m_DirString.change_from_to(forwardSlash, '/');

		int dirSize = m_DirString.get_length();
		if ( m_DirString[dirSize-1] != '/' )
			m_DirString.concatenate("/");

		selectFileUI->fileBrowser->load( m_DirString.get_char_star() );
	}
	else if ( w == selectFileUI->fileInput )
	{
		m_FileName = selectFileUI->fileInput->value();
	}
	else if ( w == selectFileUI->acceptButton )
	{
		m_AcceptFlag = true;
		selectFileUI->UIWindow->hide();
	}
	else if ( w == selectFileUI->cancelButton )
	{
		m_AcceptFlag = false;
		selectFileUI->UIWindow->hide();
	}
	else if ( w == selectFileUI->favsMenuButton )
	{
		int val = selectFileUI->favsMenuButton->value();

		if ( val == 0 )				// Add To Favorites
		{
			Fl_Preferences prefs( Fl_Preferences::USER, "NASA", "VSP");
			char favstr[256];
			sprintf( favstr, "fav%d", (int)m_FavDirVec.size() );
			prefs.set( favstr, m_DirString );
			prefs.flush();
			LoadFavsMenu();
		}
		else if ( val == 1 )	
		{
			m_FavDirVec.clear();
			Fl_Preferences prefs( Fl_Preferences::USER, "NASA", "VSP");
			for ( int i = 0 ; i < (int)prefs.entries() ; i++ )
			{
				prefs.deleteEntry( prefs.entry( i ) );
			}
			prefs.flush();
			LoadFavsMenu();	
		}
		else
		{
			//==== Select Favorite Dir ====//
			int ind = val - 2;
			if ( ind >= 0 && ind < (int)m_FavDirVec.size() )
			{
				m_DirString = m_FavDirVec[ind];
//				m_DirString.delete_range( 0, 0 );
//				m_DirString.remove_leading('/');
				selectFileUI->fileBrowser->load( m_DirString );
				selectFileUI->dirInput->value( m_DirString );
			}
		}
	}
}
示例#8
0
//=====================================================//
//===== Batch Mode Check - Parse the Command Line =====//
//=====================================================//
int batchMode(int argc, char *argv[], Aircraft* airPtr)
{

//	printf("number of args = %d : \n", argc);
//	for (int p = 0; p < argc; p++) {
//		printf("%s, ", argv[p]);
//	}
//	printf("\n");


    int i;
    int batchModeFlag = 0;
    int compgeomFlag = 0;
	int meshFlag = 0;
    int sliceFlag = 0;
	int numSlices = 0;
    int writeXsecFlag = 0;
    int writeFelisaFlag = 0;
    int writeStereoFlag = 0;
    int writeTRIFlag = 0;
    int writeRhinoFlag = 0;
    int writeNascartFlag = 0;
	int doxmlFlag = 0;
	int scriptFlag = 0;
	int feaMeshFlag = 0;
	int cfdMeshFlag = 0;
	int setTempDirFlag = 0;
	Stringc tempDirName;
	double cfdMeshScale = 1.0;
	int cfdDefaultSourcesFlag = 1;
	double Mach,sliceAngle;
	int coneSections;
	Stringc scriptFile,xmlFile;
    char airName[255];
    Stringc exec;
	int userParmFlag = 0;
	int userParmID = 0;
	double userParmVal = 0.0;

	//==== Output Names =====//
	enum { COMPGEOM_TXT, COMPGEOM_CSV, CFDMESH_STL, CFDMESH_POLY, CFDMESH_TRI, CFDMESH_OBJ,
		   CFDMESH_DAT, CFDMESH_KEY, FEAMESH_STL, FEAMESH_MASS, FEAMESH_NASTRAN, 
		   FEAMESH_CALC_GEOM, FEAMESH_CALC_THICK, COMPGEOM_DRAG, NUM_OUT_NAMES }; 

	char* outFileTypes[] = {"compgeom_txt", "compgeom_csv", "cfdmesh_stl", "cfdmesh_poly",
	                        "cfdmesh_tri",  "cfdmesh_obj",  "cfdmesh_dat", "cfdmesh_key",
	                        "feamesh_stl",  "feamesh_mass", "feamesh_nastran",
	                        "feamesh_calc_geom",  "feamesh_calc_thick", "compgeom_drag" };
	bool outNameFlags[NUM_OUT_NAMES];
	Stringc outNames[NUM_OUT_NAMES];

	for ( int i = 0 ; i < NUM_OUT_NAMES ; i++ )
		outNameFlags[i] = false;

    memset( airName, '\0', 255 );

    /* Parse the input */
    i = 1;

    while ( i <= argc - 1 ) {

       /* Do batch */
       if ( strcmp(argv[i],"-batch") == 0 ) {
		   if (i+1 < argc)
		   {
	          strcpy( airName, argv[++i] ); 
		      batchModeFlag = 1;
		   }
       }
       if ( strcmp(argv[i],"-script") == 0 ) {
		   if (i+1 < argc)
		   {
				scriptFile = argv[++i]; 
		        scriptFlag = 1;
		   }
       }
	   if ( strcmp(argv[i],"-loop") == 0 ) {
		   if (i+2 < argc)
		   {
				sscanf(argv[++i], "%f", &timerTime);
				timerScriptFile = argv[++i]; 
		        timerFlag = 1;
		   }
       }
       if ( strcmp(argv[i],"-settempdir") == 0 ) {
		   if (i+1 < argc)
		   {
				tempDirName = argv[++i]; 
		        setTempDirFlag = 1;
		   }
       }
       if ( strcmp(argv[i],"-compgeom") == 0 ) {
          compgeomFlag = 1;
       }
       if ( strcmp(argv[i],"-mesh") == 0 ) {
          meshFlag = 1;
       }
       if ( strcmp(argv[i],"-slice") == 0 ) {
		   if (i+1 < argc)
		   {
				numSlices = atoi( argv[++i] );
				Mach = atof(argv[++i] );
				sliceAngle = asin((double)1.0/(double)Mach);
				sliceAngle = RAD2DEG(sliceAngle);
				coneSections = atoi( argv[++i] );
				sliceFlag = 1;
		   }
       }
       if ( strcmp(argv[i],"-xsec") == 0 ) {
          writeXsecFlag = 1;
       }
       if ( strcmp(argv[i],"-felisa") == 0 ) {
          writeFelisaFlag = 1;
       }
       if ( strcmp(argv[i],"-stereo") == 0 ) {
          writeStereoFlag = 1;
       }
       if ( strcmp(argv[i],"-tri") == 0 ) {
          writeTRIFlag = 1;
       }
       if ( strcmp(argv[i],"-rhino") == 0 ) {
          writeRhinoFlag = 1;
       }
	   if ( strcmp(argv[i],"-nascart") == 0 ) {
          writeNascartFlag = 1;
	   }
	   if ( strcmp(argv[i],"-doxml") == 0 ) {
		   if (i+1 < argc)
		   {
			   xmlFile = argv[++i]; 	
			   doxmlFlag = 1;
		   }
	   }
	   if ( strcmp(argv[i],"-feamesh") == 0 ) {
          feaMeshFlag = 1;
	   }

       if ( strcmp(argv[i],"-cfdmesh") == 0 ) {
		   cfdMeshFlag = 1;
		   if ( (i+1 < argc) && ( argv[i+1][0] != '-' ) )
		   {
			   cfdMeshScale = atof( argv[++i] );
			   if ( cfdMeshScale <= 0 )
			   {
				printf( "invalid cfdMeshScale '%s'\n", argv[i] );
				exit( 1 );
			   }
		   }
	   }
       if ( strcmp(argv[i],"-nocfddefsources") == 0 ) {
		   cfdDefaultSourcesFlag = 0;
	   }
       if ( strcmp(argv[i],"-userparm") == 0 ) {
		   if (i+1 < argc && i+2 < argc )
		   {
		       userParmFlag = 1;
			   userParmID  = atoi( argv[++i] );
			   userParmVal = atof( argv[++i] );
		   }
	   }
      if ( strcmp(argv[i],"-outname") == 0 ) 
	   {
		   if (i+1 < argc && i+2 < argc )
		   {
			   for ( int n = 0 ; n < NUM_OUT_NAMES ; n++ )
			   {
					if ( strcmp( argv[i+1], outFileTypes[n] ) == 0 )
					{
						outNameFlags[n] = true;
						outNames[n] = argv[i+2];
						i += 2;
//printf("OutName: %s = %s \n", outFileTypes[n], outNames[n].get_char_star() );

						break;
					}
			   }
		   }
	   }

       if ( strcmp(argv[i],"-help") == 0 ) 
       {
		 printf("\n");
         printf("          %s\n",VSPVERSION1);     
         printf("--------------------------------------------\n");     
         printf("Usage: vsp [inputfile.vsp] (run interactive version)\n");
         printf("     : vsp -batch  <filename>  (batch mode)\n");
         printf("     : vsp -script <filename>  (batch mode)\n");
		 printf("     : vsp -loop <seconds> <filename> (GUI is visible)\n");
         printf("--------------------------------------------\n");     
         printf("\n");     
         printf("VSP batch options listed below:\n");     
         printf("  -compgeom          Batch run compgeom\n" );
         printf("  -slice #           Batch run slice\n" );
         printf("  -mesh              Batch run mesh\n" );
		 printf("  -cfdmesh val       Batch run CFD mesh ( val = scale tri size )\n" );
		 printf("  -nocfddefsources   Do not add default sources.\n" );
         printf("  -feamesh           Batch run fea mesh\n" );
         printf("  -xsec              Write Herm file (Vorview format) \n");
         printf("  -felisa            Write Felisa files \n");
         printf("  -stereo            Write Stereolith file \n");
         printf("  -tri               Write Cart3D file \n");
         printf("  -rhino             Write Rhino3D file \n");
         printf("  -nascart           Write Nascart file \n");
		 printf("  -doxml             Process an external xml file \n");
		 printf("  -userparm # val    Set the value of the user parm \n");
		 printf("  -tempdir pathname  Set the path name of the dir to write temp files\n");
		 printf("  -outname type name Set the filenames for output where type = \n");
		 printf("                      %s, %s, %s, %s, \n", outFileTypes[0], outFileTypes[1], outFileTypes[2], outFileTypes[3] );
		 printf("                      %s, %s, %s, %s, \n", outFileTypes[4], outFileTypes[5], outFileTypes[6], outFileTypes[7] );
		 printf("                      %s, %s, %s \n", outFileTypes[8], outFileTypes[9], outFileTypes[10] );
		 printf("                      %s, %s \n", outFileTypes[11], outFileTypes[12] );
		 //printf("                      cfdmesh_tri, cfdmesh_obj, cfdmesh_dat, cfdmesh_key, \n");
		 //printf("                      feamesh_stl, feamesh_mass, feamesh_nastran, \n");
		 //printf("                      feamesh_calc_geom, feamesh_calc_thick  \n");
		 printf("  -help              This message\n");
         printf("\n");     
         printf("--------------------------------------------\n");     
         return 1;
       }

       i++;      
    }

    if ( batchModeFlag == 0 && scriptFlag == 0 && timerFlag == 0 )
      return 0;


	if ( scriptFlag )
	{
		scriptMgr->setScriptMode(ScriptMgr::SCRIPT);
  	  ScreenMgr* screenMgrPtr = new ScreenMgr(airPtr);
	  airPtr->setScreenMgr( screenMgrPtr );
	  
	  long fileSize = 0;
	  char * buffer = NULL;

	  FILE * filePtr = fopen ( scriptFile , "rb" );
	  if (filePtr!=NULL) 
	  {
		  printf( "processing script...\n");
		  // obtain file size.
		  fseek (filePtr , 0 , SEEK_END);
		  fileSize = ftell (filePtr);
		  rewind (filePtr);

		  // allocate memory to contain the whole file.
		  buffer = (char*) malloc (fileSize+1);
		  if (buffer == NULL) exit (2);

		  // copy the file into the buffer.
		  fread (buffer,1,fileSize,filePtr);
		  buffer[fileSize] = '\0'; // add end

		  scriptMgr->parseScript(Stringc(buffer));

		  // terminate
		  fclose (filePtr);
		  free (buffer);
		  printf( "finished\n");
	  }
	  else
	  {
		  printf( "ERROR: Unable to find file.");
	  }

	}
	else if (batchModeFlag)
	{


		//==== Set Base File Name ====//
		Stringc base_name, slice_name;
 
		Stringc ram_file_name = airName;
		int vsp_loc = ram_file_name.search_for_substring(".vsp");

		if ( vsp_loc < 0 ) 
		  base_name = ram_file_name;
		else
		  base_name = ram_file_name.get_range(0, vsp_loc-1);

		//==== Read VSP File ====//
	//    ram_file_name = base_name;
	//    ram_file_name.concatenate(".vsp");

		//==== Check for File ====//
		airPtr->openFile(ram_file_name);
		airPtr->setActiveGeom( 0 );
		airPtr->update_bbox();



		if ( compgeomFlag )
		{
			//==== CompGeom File Names ====//
			if ( outNameFlags[COMPGEOM_TXT] )
			{
				airPtr->setExortFileName( outNames[0], Aircraft::COMP_GEOM_TXT_TYPE );
			}
			if ( outNameFlags[COMPGEOM_CSV] )
			{
				airPtr->setExportCompGeomCsvFile( true );
				airPtr->setExortFileName( outNames[1], Aircraft::COMP_GEOM_CSV_TYPE );
			}
			if ( outNameFlags[COMPGEOM_DRAG] )
			{
				airPtr->setExportDragBuildTsvFile( true );
				airPtr->setExortFileName( outNames[COMPGEOM_DRAG], Aircraft::DRAG_BUILD_TSV_TYPE );
			}

			Geom* geom = airPtr->comp_geom(0);
		}
		if ( meshFlag )
		{
			Geom* geom = airPtr->comp_geom(0, 1);
		}
		if ( feaMeshFlag )
		{
			//==== FeaMesh Names ====//
			if ( outNameFlags[FEAMESH_STL] )
				feaMeshMgrPtr->SetFeaExportFileName( outNames[FEAMESH_STL], FeaMeshMgr::STL_FEA_NAME );
			if ( outNameFlags[FEAMESH_MASS] )
				feaMeshMgrPtr->SetFeaExportFileName( outNames[FEAMESH_MASS], FeaMeshMgr::MASS_FILE_NAME );
			if ( outNameFlags[FEAMESH_NASTRAN] )
				feaMeshMgrPtr->SetFeaExportFileName( outNames[FEAMESH_NASTRAN], FeaMeshMgr::NASTRAN_FILE_NAME );
			if ( outNameFlags[FEAMESH_CALC_GEOM] )
				feaMeshMgrPtr->SetFeaExportFileName( outNames[FEAMESH_CALC_GEOM], FeaMeshMgr::GEOM_FILE_NAME );
			if ( outNameFlags[FEAMESH_CALC_THICK] )
				feaMeshMgrPtr->SetFeaExportFileName( outNames[FEAMESH_CALC_THICK], FeaMeshMgr::THICK_FILE_NAME );

			feaMeshMgrPtr->SetBatchFlag( true );
			feaMeshMgrPtr->LoadSurfaces();
			feaMeshMgrPtr->Build();
			feaMeshMgrPtr->Export();
		}
		if ( userParmFlag )
		{
			airPtr->getUserGeom()->SetUserParmValue( userParmID, userParmVal );
			airPtr->update_bbox();
		}

		if (sliceFlag)
		{
			slice_name = Stringc("slice.txt");
			Geom* geom = airPtr->slice(2,numSlices,(double)sliceAngle,(double)coneSections,slice_name);
		}
		if ( cfdMeshFlag )
		{
			//==== CFD Mesh File Names ====//
			if ( outNameFlags[CFDMESH_STL] )
				cfdMeshMgrPtr->SetExportFileName( outNames[CFDMESH_STL], CfdMeshMgr::STL_FILE_NAME );
			if ( outNameFlags[CFDMESH_POLY] )
				cfdMeshMgrPtr->SetExportFileName( outNames[CFDMESH_POLY], CfdMeshMgr::POLY_FILE_NAME );
			if ( outNameFlags[CFDMESH_TRI] )
				cfdMeshMgrPtr->SetExportFileName( outNames[CFDMESH_TRI], CfdMeshMgr::TRI_FILE_NAME );
			if ( outNameFlags[CFDMESH_OBJ] )
				cfdMeshMgrPtr->SetExportFileName( outNames[CFDMESH_OBJ], CfdMeshMgr::OBJ_FILE_NAME );
			if ( outNameFlags[CFDMESH_DAT] )
				cfdMeshMgrPtr->SetExportFileName( outNames[CFDMESH_DAT], CfdMeshMgr::DAT_FILE_NAME );
			if ( outNameFlags[CFDMESH_KEY] )
				cfdMeshMgrPtr->SetExportFileName( outNames[CFDMESH_KEY], CfdMeshMgr::KEY_FILE_NAME );

			cfdMeshMgrPtr->SetBatchFlag( true );
			Stringc bezTempFile = airPtr->getTempDir();
			bezTempFile.concatenate( Stringc( "cfdmesh.bez" ) );

			airPtr->write_bezier_file( bezTempFile );
			cfdMeshMgrPtr->CleanUp();
			cfdMeshMgrPtr->ReadSurfs( bezTempFile );
			cfdMeshMgrPtr->UpdateSources();
			if ( cfdDefaultSourcesFlag )
			{
				cfdMeshMgrPtr->AddDefaultSources();
				cfdMeshMgrPtr->UpdateSources();
			}
			cfdMeshMgrPtr->ScaleTriSize( cfdMeshScale );
			cfdMeshMgrPtr->BuildGrid();
			cfdMeshMgrPtr->Intersect();
			cfdMeshMgrPtr->UpdateSources();
			cfdMeshMgrPtr->InitMesh();
			cfdMeshMgrPtr->Remesh( CfdMeshMgr::NO_OUTPUT );

			//Stringc stereo_file_name = base_name;
			//stereo_file_name.concatenate(".stl");
			//cfdMeshMgrPtr->WriteSTL( stereo_file_name );
			//Stringc bodyin_dat_file_name = base_name;
			//bodyin_dat_file_name.concatenate("bodyin.dat");
			//Stringc bodyin_key_file_name = base_name;
			//bodyin_key_file_name.concatenate("bodyin.key");

//			cfdMeshMgrPtr->WriteNASCART(bodyin_dat_file_name, bodyin_key_file_name );
			//cfdMeshMgrPtr->WriteTetGen("tetgen.poly");
			Stringc resultTxt = cfdMeshMgrPtr->CheckWaterTight();
			printf( resultTxt.get_char_star() );

			fflush( stdout );

			cfdMeshMgrPtr->SetExportFileFlag( true, CfdMeshMgr::STL_FILE_NAME );
			cfdMeshMgrPtr->SetExportFileFlag( true, CfdMeshMgr::POLY_FILE_NAME );
			cfdMeshMgrPtr->SetExportFileFlag( true, CfdMeshMgr::TRI_FILE_NAME );
			cfdMeshMgrPtr->SetExportFileFlag( true, CfdMeshMgr::OBJ_FILE_NAME );
			cfdMeshMgrPtr->SetExportFileFlag( true, CfdMeshMgr::DAT_FILE_NAME );
			cfdMeshMgrPtr->SetExportFileFlag( true, CfdMeshMgr::KEY_FILE_NAME );

			cfdMeshMgrPtr->ExportFiles();
		}


		if ( writeXsecFlag )
		{
		  Stringc xsec_vorview_file_name = base_name;
		  xsec_vorview_file_name.concatenate(".hrm");

		  airPtr->write_xsec_file( xsec_vorview_file_name );
		  printf( "xsec file name = %s\n",  xsec_vorview_file_name() );
		}

		if ( writeFelisaFlag )
		{
		  Stringc felisa_file_name = base_name;
		  felisa_file_name.concatenate(".fel");

		  Stringc felisa_background_file_name = base_name;
		  felisa_background_file_name.concatenate(".bac");

		  Stringc fps3d_bco_file_name = base_name;
		  fps3d_bco_file_name.concatenate(".bsf");

  		  airPtr->write_felisa_file( felisa_file_name );
		  airPtr->write_felisa_background_file( felisa_background_file_name );
		  airPtr->write_fps3d_bco_file( fps3d_bco_file_name );
		  printf( "felissa file name = %s, %s, %s\n",  felisa_file_name(), felisa_background_file_name(), fps3d_bco_file_name() );
		}
		if ( writeStereoFlag )
		{
		  Stringc stereo_file_name = base_name;
		  stereo_file_name.concatenate(".stl");

  		  airPtr->write_stl_file( stereo_file_name );
		  printf( "stereolith file name = %s\n",  stereo_file_name());
		}
		if ( writeTRIFlag )
		{
		  Stringc tri_file_name = base_name;
		  tri_file_name.concatenate(".tri");

  		  airPtr->write_cart3d_files( tri_file_name );
		  printf( "cart3d file name = %s\n",  tri_file_name());
		}
		if ( writeRhinoFlag )
		{
		  Stringc rhino_file_name = base_name;
		  rhino_file_name.concatenate(".3dm");

  		  airPtr->write_rhino_file( rhino_file_name );
		  printf( "rhino3d file name = %s\n",  rhino_file_name());
		}
		if ( writeNascartFlag )
		{
			//==== Extract Path ====//
			Stringc nascart_file_name = base_name;

			int last = -1;
			for ( i = 0 ; i < nascart_file_name.get_length() ; i++ )
			{
				if ( nascart_file_name[i] == '/' )
					last = i;
			}

			if ( last == -1 )
				nascart_file_name = Stringc("bodyin.dat");

			else
			{
				nascart_file_name.delete_range(last+1,nascart_file_name.get_length()-1);
				nascart_file_name.concatenate( "bodyin.dat" );
			}

			airPtr->write_nascart_files( nascart_file_name );
			printf( "nascart file name = %s\n",  nascart_file_name());
		}
		if ( setTempDirFlag )
		{
			airPtr->setTempDir( tempDirName, true );
		}
		



	}
    return (batchModeFlag || scriptFlag);

}
示例#9
0
void GeomScreen::s_add_geom(int src, int type, Stringc name)
{
	Geom* addGeom = 0;
	lastSelectedGeom = NULL;

	if ( type == POD_GEOM_TYPE )
	{
		addGeom = aircraftPtr->createGeom(POD_GEOM_TYPE);
	}
	else if ( type == WING_GEOM_TYPE )
	{
		addGeom = aircraftPtr->createGeom(WING_GEOM_TYPE);
	}
	else if ( type == FUSE_GEOM_TYPE )
	{
		addGeom = aircraftPtr->createGeom(FUSE_GEOM_TYPE);
	}
	else if ( type == HAVOC_GEOM_TYPE )
	{
		addGeom = aircraftPtr->createGeom(HAVOC_GEOM_TYPE);
	}
	else if ( type == EXT_GEOM_TYPE )
	{
		addGeom = aircraftPtr->createGeom(EXT_GEOM_TYPE);
	}
	else if ( type == MS_WING_GEOM_TYPE )
	{
		addGeom = aircraftPtr->createGeom(MS_WING_GEOM_TYPE);
	}
	else if ( type == BLANK_GEOM_TYPE )
	{
		addGeom = aircraftPtr->createGeom(BLANK_GEOM_TYPE);
	}
	else if ( type == DUCT_GEOM_TYPE )
	{
		addGeom = aircraftPtr->createGeom(DUCT_GEOM_TYPE);
	}
	else if ( type == PROP_GEOM_TYPE )
	{
		addGeom = aircraftPtr->createGeom(PROP_GEOM_TYPE);
	}
	else if ( type == ENGINE_GEOM_TYPE )
	{
		addGeom = aircraftPtr->createGeom(ENGINE_GEOM_TYPE);
	}
	else if ( type == HWB_GEOM_TYPE )
	{
		addGeom = aircraftPtr->createGeom(HWB_GEOM_TYPE);
	}
	else if ( type == FUSELAGE_GEOM_TYPE )
	{
		addGeom = aircraftPtr->createGeom(FUSELAGE_GEOM_TYPE);
	}
	else if ( type == CABIN_LAYOUT_GEOM_TYPE )
	{
		addGeom = aircraftPtr->createGeom(CABIN_LAYOUT_GEOM_TYPE);
	}

	if (addGeom && name.get_length() > 0)
	{
		addGeom->setName(name);
	}

	if (src != ScriptMgr::SCRIPT)
	{
		loadGeomBrowser();
		deselectGeomBrowser();

		if ( addGeom )
			selectGeomBrowser(addGeom);

		loadActiveGeomOutput();
		screenMgrPtr->updateGeomScreens();
		aircraftPtr->flagActiveGeom();
		loadGeomBrowser();

		if ( addGeom )
		{
			if (src == ScriptMgr::GUI) scriptMgr->addLine("add", addGeom->getTypeStr(), addGeom->getName());
		}
	}
}
示例#10
0
void PHolderListMgr::ReadPHolderListXDDM( char *newfile )
{
	pHolderListMgrPtr->DelAllPHolders();

	//==== Read Xml File ====//
	xmlDocPtr doc;
	xmlNodePtr node;

	LIBXML_TEST_VERSION
	xmlKeepBlanksDefault(0);

	//==== Build an XML tree from a the file ====//
	doc = xmlParseFile(newfile);
//			if (doc == NULL) return 0;

	xmlNodePtr root = xmlDocGetRootElement(doc);
	if (root == NULL)
	{
		fprintf(stderr,"empty document\n");
		xmlFreeDoc(doc);
//				return 0;
	}

	vector< Geom* > gVec = aircraftPtr->getGeomVec();
	gVec.push_back( aircraftPtr->getUserGeom() );

	vector< xmlNodePtr > vlist;

	int num_v = xmlGetNumNames( root, "Variable" );
	for ( int i = 0 ; i < num_v ; i++ )
	{
		xmlNodePtr var_node = xmlGetNode( root, "Variable", i );
		vlist.push_back( var_node );
	}

	int num_c = xmlGetNumNames( root, "Constant" );
	for ( int i = 0 ; i < num_c ; i++ )
	{
		xmlNodePtr cst_node = xmlGetNode( root, "Constant", i );
		vlist.push_back( cst_node );
	}

	int num_tot = num_v + num_c;

	for ( int i = 0 ; i < num_tot ; i++ )
	{
		xmlNodePtr var_node = vlist[i];

		if ( var_node )
		{
			Stringc varname = Stringc( xmlFindPropString( var_node, "VSPVarName", " " ) );

			int istart = 0;
			int iend = varname.search_for_substring(':');
			int id = varname.get_range( istart, iend-1 ).convert_to_integer();

			istart = iend + 1;
			iend = varname.search_for_substring( istart, ':' );
			istart = iend + 1;
			iend = varname.search_for_substring( istart, ':' );
			Stringc group = varname.get_range( istart, iend-1 );

			istart = iend + 1;
			iend = varname.get_length();
			Stringc parm = varname.get_range( istart, iend-1 );

			Parm* p = parmMgrPtr->FindParm( gVec, id, group, parm );

			if ( p )
			{
				double val = xmlFindPropDouble( var_node, "Value", p->get() );

				p->set_from_link( val );
				p->get_geom()->parm_changed( p );

				ParmHolder* ph = new ParmHolder();
				ph->setParm( p );

				const xmlChar* varstr = (xmlChar*) "Variable";

				if( !xmlStrcmp(var_node->name, varstr ) )
					ph->setDesType( XDDM_VAR );
				else
					ph->setDesType( XDDM_CONST );

				m_PHolderVec.push_back( ph );
				m_CurrPHolderIndex = (int)m_PHolderVec.size() - 1;
			}
		}
	}

	//===== Free Doc =====//
	xmlFreeDoc( doc );

//			return 1;
}
示例#11
0
void GeomScreen::screenCB( Fl_Widget* w )
{

	if ( w == geomUI->addGeomButton )
	{
		int type = geomUI->geomTypeChoice->value();

		if ( type >= WING_GEOM_TYPE )			// Compensate for removing Wing Type
			type += 1;

		s_add_geom(ScriptMgr::GUI, type, Stringc(""));
	}
	else if ( w == geomUI->geomBrowser)
	{
		s_select_gui();
	}
	else if ( w == geomUI->noshowGeomButton )
	{
		vector<Geom*> selVec = getSelectedGeomVec();

		for ( int i = 0 ; i < (int)selVec.size() ; i++ )
		{
			selVec[i]->setNoShowFlag( 1 );
		}
		aircraftPtr->triggerDraw();
		loadGeomBrowser();
	}
	else if ( w == geomUI->showGeomButton )
	{
		vector<Geom*> selVec = getSelectedGeomVec();

		for ( int i = 0 ; i < (int)selVec.size() ; i++ )
		{
			selVec[i]->setNoShowFlag( 0 );
		}
		aircraftPtr->triggerDraw();
		loadGeomBrowser();

	}
	else if ( w == geomUI->selectAllGeomButton )
	{
		s_select_all(ScriptMgr::GUI);
	}
	else if ( w == geomUI->activeGeomInput )
	{
		Geom* activeGeom = aircraftPtr->getActiveGeom();
		if ( activeGeom )
		{
			Stringc name = geomUI->activeGeomInput->value();
			activeGeom->setName( name );
			loadGeomBrowser();

			name.quote('\"');
			scriptMgr->addLine("gen", "name", name);		}
		else
		{
			aircraftPtr->setName( geomUI->activeGeomInput->value() );
			loadGeomBrowser();
		}

		vector<Geom*> selVec = getSelectedGeomVec();

		if ( selVec.size() == 1 )
			aircraftPtr->modifyGeom( selVec[0] );
	}
	else if ( w == geomUI->cutGeomButton )
	{
		s_cut(ScriptMgr::GUI, deque< Stringc >());
	}
	else if ( w == geomUI->copyGeomButton )
	{
		s_copy(ScriptMgr::GUI, deque< Stringc >());
	}
	else if ( w == geomUI->pasteGeomButton )
	{
		s_paste(ScriptMgr::GUI);
	}
	else if ( w == geomUI->wireGeomButton )
	{
		setGeomDisplayFlag( GEOM_WIRE_FLAG );
	}
	else if ( w == geomUI->hiddenGeomButton )
	{
		setGeomDisplayFlag( GEOM_HIDDEN_FLAG );
	}
	else if ( w == geomUI->shadeGeomButton )
	{
		setGeomDisplayFlag( GEOM_SHADE_FLAG );
	}
	else if ( w == geomUI->textureGeomButton )
	{
		setGeomDisplayFlag( GEOM_TEXTURE_FLAG );
	}
	else if ( w == geomUI->moveUpButton )
	{
		aircraftPtr->reorderGeom( Aircraft::MOVE_UP );
		deselectGeomBrowser();
			
		Geom * activeGeom = aircraftPtr->getActiveGeom();
		if ( activeGeom )
			selectGeomBrowser(activeGeom);
		loadGeomBrowser();
	}
	else if ( w == geomUI->moveDownButton )
	{
		aircraftPtr->reorderGeom( Aircraft::MOVE_DOWN );
		deselectGeomBrowser();

		Geom * activeGeom = aircraftPtr->getActiveGeom();
		if ( activeGeom )
			selectGeomBrowser(activeGeom);
		loadGeomBrowser();
	}
	else if ( w == geomUI->moveTopButton )
	{
		aircraftPtr->reorderGeom( Aircraft::MOVE_TOP );
		deselectGeomBrowser();
			
		Geom * activeGeom = aircraftPtr->getActiveGeom();
		if ( activeGeom )
			selectGeomBrowser(activeGeom);
		loadGeomBrowser();
	}
	else if ( w == geomUI->moveBotButton )
	{
		aircraftPtr->reorderGeom( Aircraft::MOVE_BOT );
		deselectGeomBrowser();
			
		Geom * activeGeom = aircraftPtr->getActiveGeom();
		if ( activeGeom )
			selectGeomBrowser(activeGeom);
		loadGeomBrowser();
	}
	else if ( w == geomUI->defaultAircraftTypeChoice )
	{
		int id = geomUI->defaultAircraftTypeChoice->value();
		VspPreferences::Instance()->setDefaultCompFileID( id );
		aircraftPtr->setDefaultCompGroupID(id);
	}

}
示例#12
0
//===== Read AF File =====//
int FuselageXSec::read_xsec_file( Stringc file_name )
{
  int i;
  Stringc line;
  char buff[255];

  //==== Open file ====//
  FILE* file_id = fopen(file_name, "r");
  if (file_id == (FILE *)NULL) return(0);

  fgets(buff, 80, file_id);  line = buff;
  if (line.search_for_substring("FUSE XSEC FILE") < 0)
    return 0;

  char name[255];
  int num_pnts;
  float y, z;

  fscanf(file_id, "%s", name);       fgets(buff, 80, file_id);
  fileName = name;
  fscanf(file_id, "%d", &num_pnts);  fgets(buff, 80, file_id);

  file_crv.init( num_pnts );
  for ( i = 0 ; i < num_pnts ; i++ )
  {
    fscanf(file_id, "%f  %f", &y, &z);  fgets(buff, 80, file_id);
    file_crv.load_pnt( i, vec3d( 0.0, y,  z ));
  }

  //==== Find Height & Width ====//
  vec3d p0 = file_crv.get_pnt( 0 );
  vec3d pn = file_crv.get_pnt( num_pnts-1 );
  height = fabs(p0.z() - pn.z());

  double max_y = 0;
  for ( i = 0 ; i < num_pnts ; i++ )
  {
    double y = file_crv.get_pnt( i ).y();
    if  ( fabs(y) > max_y )
      max_y = fabs(y);
  }
  width = (2.0*max_y);

  //==== Scale Point By Height & Width ====//
  for ( i = 0 ; i < num_pnts ; i++ )
  {
    double y = 2.0*file_crv.get_pnt( i ).y()/width();
    double z = 2.0*file_crv.get_pnt( i ).z()/height();
    file_crv.load_pnt( i, vec3d( 0.0, y,  z ));
  }

  file_crv.comp_tans();
  vec3d top_tan = vec3d( 0.0, 1.0, 0.0 );
  double tan_mag = (file_crv).get_tan(0).mag();

  file_crv.load_tan( 0, top_tan*tan_mag );
  int last_id =  file_crv.get_num_pnts() - 1;
  vec3d bot_tan = vec3d( 0.0, -1.0, 0.0 );
  tan_mag = file_crv.get_tan( last_id ).mag();
  file_crv.load_tan( last_id, bot_tan*tan_mag );

  fclose(file_id);

  return 1;
}
示例#13
0
void PHolderListMgr::ReadPHolderListDES( char *newfile )
{
	FILE *fp;
	fp = fopen( newfile, "r" );
	char temp[255];

	fgets( temp, 255, fp );
	Stringc line = temp;
	int nparm = line.convert_to_integer();

	if( nparm > 0 )
	{
		pHolderListMgrPtr->DelAllPHolders();

		vector< Geom* > gVec = aircraftPtr->getGeomVec();
		gVec.push_back( aircraftPtr->getUserGeom() );


		for ( int i = 0 ; i < nparm ; i++ )
		{
			fgets( temp, 255, fp );
			line = temp;

			int istart = 0;
			int iend = line.search_for_substring(':');
			int id = line.get_range( istart, iend-1 ).convert_to_integer();

			istart = iend + 1;
			iend = line.search_for_substring( istart, ':' );
			istart = iend + 1;
			iend = line.search_for_substring( istart, ':' );
			Stringc group = line.get_range( istart, iend-1 );

			istart = iend + 1;
			iend = line.search_for_substring( istart, ':' );
			Stringc parm = line.get_range( istart, iend-1 );

			istart = iend + 1;
			iend = line.get_length();
			double val = line.get_range( istart, iend-1 ).convert_to_double();

			Parm* p = parmMgrPtr->FindParm( gVec, id, group, parm );

			if ( p )
			{
				p->set_from_link( val );
				p->get_geom()->parm_changed( p );

				ParmHolder* ph = new ParmHolder();
				ph->setParm( p );

				m_PHolderVec.push_back( ph );
				m_CurrPHolderIndex = (int)m_PHolderVec.size() - 1;
			}
		}
	}
	fclose( fp );
}
示例#14
0
//==== Read Airfoil File ====//
void Af::read(FILE* file_id)
{
  int i;
  Stringc line;
  char buff[255];
  int temp_type;
  int version = geom_ptr->get_aircraft_ptr()->get_version();

  fgets(buff, 80, file_id);
  fgets(buff, 80, file_id);  line = buff;

  if (line.search_for_substring("Num") >= 0)
    {
      sscanf(buff, "%d", &num_pnts);
      if (version >= 5) 
      {
        fscanf(file_id, "%d", &inverted_flag);
        fgets(buff, 80, file_id);
      }
      camber.read(file_id);
      camber_loc.read(file_id);
      thickness.read(file_id);
      temp_type = NACA_4_SERIES;
    }
  else
    {
      sscanf(buff, "%d", &temp_type);
      if (version >= 5)
      {
        fscanf(file_id, "%d", &inverted_flag);
        fgets(buff, 80, file_id);
      }
      camber.read(file_id);
      camber_loc.read(file_id);
      thickness.read(file_id);
      thickness_loc.read(file_id);
      radius_le.read(file_id);
      radius_te.read(file_id);

      if ( temp_type ==  NACA_6_SERIES )
      {
        fscanf( file_id, "%d", &sixser );
        fgets(buff, 80, file_id);
        ideal_cl.read(file_id);
        a.read(file_id);
      }

      if ( temp_type == AIRFOIL_FILE )
        {
          fgets(buff, 80, file_id);
          name = buff;
          name.remove_trailing_blanks();
          name.remove_all_substrings('\n');

          vec3d pnt;
          float x, z;
          int num_upper, num_lower;

          fscanf(file_id, "%f",&orig_af_thickness);		fgets(buff, 80, file_id);
          fscanf(file_id, "%f",&radius_le_correction_factor);	fgets(buff, 80, file_id);
          fscanf(file_id, "%f",&radius_te_correction_factor);	fgets(buff, 80, file_id);
          fscanf(file_id, "%d",&num_upper); 			fgets(buff, 80, file_id);
          upper_curve.init(num_upper);
          for ( i = 0 ; i < num_upper ; i++)
            {
              fscanf(file_id, "%f  %f",&x, &z);
              pnt = vec3d(x, 0.0, z);
              upper_curve.load_pnt( i, pnt );
            }
          fgets(buff, 80, file_id);
          fscanf(file_id, "%d",&num_lower); 			fgets(buff, 80, file_id);
          lower_curve.init(num_lower);
          for (  i = 0 ; i < num_lower ; i++)
            {
              fscanf(file_id, "%f  %f",&x, &z);
              pnt = vec3d(x, 0.0, z);
              lower_curve.load_pnt( i, pnt );
            }
          fgets(buff, 80, file_id);
        }
     }
  set_type(temp_type);
}
示例#15
0
void Af::write(xmlNodePtr node)
{
  int i;

  xmlAddIntNode( node, "Type", type);
  xmlAddIntNode( node, "Inverted_Flag", inverted_flag);

  xmlAddDoubleNode( node, "Camber", camber() );
  xmlAddDoubleNode( node, "Camber_Loc", camber_loc() );
  xmlAddDoubleNode( node, "Thickness",  thickness() );
  xmlAddDoubleNode( node, "Thickness_Loc",  thickness_loc() );

  xmlAddDoubleNode( node, "Radius_Le",  radius_le() );
  xmlAddDoubleNode( node, "Radius_Te",  radius_te() );

  xmlAddIntNode( node, "Six_Series",  sixser );
  xmlAddDoubleNode( node, "Ideal_Cl",  ideal_cl() );
  xmlAddDoubleNode( node, "A",  a() );

  if ( type == AIRFOIL_FILE )
  {
    xmlAddStringNode( node, "Name",  name() );
    xmlAddDoubleNode( node, "Original_AF_Thickness",  orig_af_thickness );
    xmlAddDoubleNode( node, "Radius_LE_Correction_Factor",  radius_le_correction_factor );
    xmlAddDoubleNode( node, "Radius_TE_Correction_Factor",  radius_te_correction_factor );

    vec3d pnt;
    Stringc upstr;
    char numstr[255];
    for (  i = 0 ; i < upper_curve.get_num_pnts() ; i++)
    {
      pnt = upper_curve.get_pnt(i);
      sprintf( numstr, "%lf, %lf,", pnt.x(), pnt.z() );
      upstr.concatenate(numstr);
    }
    upstr.concatenate("\0");

    xmlAddStringNode( node, "Upper_Pnts", upstr );

   Stringc lowstr;
    for (  i = 0 ; i < lower_curve.get_num_pnts() ; i++)
    {
      pnt = lower_curve.get_pnt(i);
      sprintf( numstr, "%lf, %lf,", pnt.x(), pnt.z() );
      lowstr.concatenate(numstr);
    }
    lowstr.concatenate("\0");

    xmlAddStringNode( node, "Lower_Pnts", lowstr );
  }

  xmlAddIntNode( node, "Slat_Flag",  slat_flag );
  xmlAddIntNode( node, "Slat_Shear_Flag",  slat_shear_flag );
  xmlAddDoubleNode( node, "Slat_Chord",  slat_chord() );
  xmlAddDoubleNode( node, "Slat_Angle",  slat_angle() );

  xmlAddIntNode( node, "Flap_Flag",  flap_flag );
  xmlAddIntNode( node, "Flap_Shear_Flag",  flap_shear_flag );
  xmlAddDoubleNode( node, "Flap_Chord",  flap_chord() );
  xmlAddDoubleNode( node, "Flap_Angle",  flap_angle() );

}
示例#16
0
int Af::readVspAirfoil( FILE* file_id,
		int *thickness_read_flag, int *radius_le_read_flag, int *radius_te_read_flag  )
{
   int i;
   Stringc line;
   char buff[256];

   fgets(buff, 255, file_id);
   name = buff;
   name.remove_trailing_blanks();
   name.remove_all_substrings('\n');

   int sym_flag;
   int num_pnts_upper, num_pnts_lower;
   float x, z;

   fscanf(file_id, "%d", &sym_flag);
   fgets(buff, 255, file_id);

   fscanf(file_id, "%d", &num_pnts_upper);
   fgets(buff, 255, file_id);

    upper_curve.init(num_pnts_upper);
    if (sym_flag)
     {
       num_pnts_lower = num_pnts_upper;
       lower_curve.init(num_pnts_lower);
     }
   else
     {
       fscanf(file_id, "%d", &num_pnts_lower);
       fgets(buff, 255, file_id);
       lower_curve.init(num_pnts_lower);
     }

   for (i = 0 ; i < num_pnts_upper ; i++)
     {
       fscanf(file_id, "%f %f", &x, &z);
       fgets(buff, 255, file_id);

       upper_curve.load_pnt(  i, vec3d(x, 0.0, z));

       if ( sym_flag )
         {
           lower_curve.load_pnt(  i, vec3d(x, 0.0, -z) );
         }
     }
   fgets(buff, 255, file_id);


  if ( !sym_flag )
    {
      for ( i = 0 ; i < num_pnts_lower ; i++)
        {
          fscanf(file_id, "%f %f", &x, &z);
          fgets(buff, 255, file_id);
          lower_curve.load_pnt( i, vec3d(x, 0.0, z) );
        }
      fgets(buff, 255, file_id);
    }

  //==== Close Trailing Edge - Set Last Points ====//
  vec3d last_pnt = upper_curve.get_pnt(num_pnts_upper-1) + 
                   lower_curve.get_pnt(num_pnts_lower-1);
  upper_curve.load_pnt(num_pnts_upper-1, last_pnt*0.5);
  lower_curve.load_pnt(num_pnts_lower-1, last_pnt*0.5);

  float fdum;  
  int more_data_flag = 1;
  while (more_data_flag)
    {
      more_data_flag = 0;
      if ( fgets(buff, 255, file_id) )
        {
          more_data_flag = 1;
          line = buff;
        }
      else
        {
          line = " ";
        }

      if (line.search_for_substring("Radius") >= 0)
        {
          sscanf(buff, "%f", &fdum);
         if (line.search_for_substring("Trailing") >= 0)
            {
              radius_te = fdum;
              *radius_te_read_flag = 1;
            }
          else
            {
              radius_le = fdum;
              *radius_le_read_flag = 1;
            }
        }
      if (line.search_for_substring("Thick") >= 0)
        {
          sscanf(buff, "%f", &fdum);
          if (line.search_for_substring("Location") >= 0)
            {
              thickness_loc = fdum;
            }
          else
            {
              *thickness_read_flag = 1;
              thickness = fdum;
            }
        }
      if (line.search_for_substring("Camber") >= 0)
        {
          sscanf(buff, "%f", &fdum);
          if (line.search_for_substring("Location") >= 0)
            {
              camber_loc = fdum;
            }
          else
            {
              camber = fdum;
            }
        }
      if (line.search_for_substring("Delta") >= 0)
        {
          sscanf(buff, "%f", &fdum);
          delta_y_le = fdum;
        }
    }

  fclose(file_id);

	return 1;

}
示例#17
0
//===== Read AF File =====//
int Af::read_af_file( Stringc file_name )
{
  Stringc line;
  char buff[255];
  int thickness_read_flag = 0;
  int radius_le_read_flag = 0;
  int radius_te_read_flag = 0;
  
  /* --- Open file --- */
  FILE* file_id = fopen(file_name, "r");

  if (file_id == (FILE *)NULL) return(0);

  fgets(buff, 255, file_id);  line = buff;

	int ok = 0;
	if (line.search_for_substring("AIRFOIL FILE") < 0)
	{
		ok = readSeligAirfoil( file_id );	

		if ( ok )
		{
    		name = buff;
    		name.remove_trailing_blanks();
   			name.remove_all_substrings('\n');
   			name.remove_all_substrings('\r');
		}	
		else
		{
			ok = readLednicerAirfoil( file_id );	
		}

	}
	else
	{
		ok = readVspAirfoil( file_id, &thickness_read_flag, &radius_le_read_flag, &radius_te_read_flag );
	}

  fclose( file_id );

  if ( !ok )
	  return 0;

  //==== Set Type and Deactivate Parameters ====//
  set_type( AIRFOIL_FILE );

  //==== Check if  Thickness was in File - Compute if not ====//
  if ( !thickness_read_flag )
    thickness = compute_thickness_af_curves();

  //==== Set Base Thickness Value ====//
  orig_af_thickness = (float)thickness();

  //==== Check if  Radius LE was in File - Compute if not ====//
  if ( !radius_le_read_flag )
    {
      radius_le = compute_radius_le_af_curves();
      radius_le_correction_factor = 1.0;
    }
  else
    {
      radius_le_correction_factor = (float)(radius_le()/compute_radius_le_af_curves());
    }

  //==== Check if  Radius TE was in File - Compute if not ====//
  if ( !radius_te_read_flag )
    {
      radius_te = 0.0;
    }

  upper_curve.comp_tans();
  lower_curve.comp_tans();

  vec3d leading_edge_tan = vec3d(0.0, 0.0, 1.0);

  double tan_mag = upper_curve.get_tan(0).mag();
  upper_curve.load_tan( 0, leading_edge_tan*tan_mag);

  tan_mag = -(lower_curve.get_tan(0).mag());
  lower_curve.load_tan( 0, leading_edge_tan*tan_mag);

  generate_from_file_curve();

  return(1);

}