Beispiel #1
0
void BuildAtom::rightMousePressEvent(QMouseEvent* e) 
{
   int nObjects(m_viewer->m_objects.size());
   if ((m_beginAtom == 0) && 
       (nObjects > 0) && 
       (e->modifiers() != int(Viewer::s_buildModifier))) {
      // Manipulating in Build mode
      e->ignore();
      return;
   }

   initPointers();
   if (m_viewer->m_selectedObjects.isEmpty()) return;

   m_deleteTarget  = m_beginAtom;

   if (m_deleteTarget == 0) {
      // Should really check for a primitive
      m_deleteTarget = m_viewer->m_selectedObjects[0];
   }

   // Determine the parent molecule
   if (m_molecule == 0) {
      MoleculeList parents(m_deleteTarget->findLayers<Layer::Molecule>(Layer::Parents));
      if (parents.isEmpty()) {
         m_molecule = m_viewer->m_viewerModel.activeMolecule();
      }else {
         m_molecule = parents.first();
      }
   }

   if (m_deleteTarget) m_manipulateOnly = false;
   if (!m_molecule) qDebug() << "Molecule not set in buidler";
   e->accept();
}
Beispiel #2
0
void BuildAtom::leftMousePressEvent(QMouseEvent* e) 
{
   int nObjects(m_viewer->m_objects.size());
   if ((m_beginAtom == 0) && 
       (nObjects > 0)     && 
       (e->modifiers() != int(Viewer::s_buildModifier))) {
      // Manipulating in Build mode
      e->ignore();
      return;
   }

   initPointers();
   m_manipulateOnly = false;

   if (m_beginAtom == 0) {
	  // We need to create the first atom, this only happens at the start of a
	  // build or the first atom of a fragment.  In either case, once we have
	  // created the atom we post the command and do not activate the build.
	  // This ensures only a single atom is created.
      Vec v(m_viewer->worldCoordinatesOf(e));
      m_beginAtom = m_molecule->createAtom(m_buildElement, v);
      m_buildObjects.append(m_beginAtom);
   }

   m_viewer->setMouseBinding(Qt::LeftButton, QGLViewer::FRAME, QGLViewer::TRANSLATE);
   m_viewer->updateGL();
   e->accept();
}
Beispiel #3
0
ThreadPool::ThreadPool(int initThreads, int maxThreads,bool console) {
	this->console = console;
	this->lowp = -1;
	this->highp = -1;
	this->initThreads = initThreads;
	this->maxThreads = maxThreads;
	this->runFlag = false;
	joinComplete = false;
	prioritypooling = false;
	initPointers();
	initializeThreads();
}
	void Shader::init()
	{
		initPointers();
		loadVertex();

		if (d_n_geometry != 0)
			loadGeometry();

		loadFragment();
		compile();
		link();
	}
Beispiel #5
0
void project_open(char *f1, char *f2, char *f3)
//
//  Input:   f1 = pointer to name of input file
//           f2 = pointer to name of report file
//           f3 = pointer to name of binary output file
//  Output:  none
//  Purpose: opens a new SWMM project.
//
{
    initPointers();
    setDefaults();
    openFiles(f1, f2, f3);
}
Beispiel #6
0
void PLDIBSection::internalCreate
    ( PLLONG Width,
      PLLONG Height,
      const PLPixelFormat& pf
    )
    // Create a new empty DIBSection.
    // Assumes that no memory is allocated before the call.
{
#ifdef MAX_BITMAP_SIZE
	if (GetMemNeeded (Width, Height, pf.GetBitsPerPixel())
      > MAX_BITMAP_SIZE)
	  throw PLTextException(PL_ERRDIB_TOO_LARGE, "Bitmap size too large.\n");
#endif

  int MemNeeded = sizeof (BITMAPINFOHEADER);
  if (pf.GetBitsPerPixel() <= 8)
  { // Color table exists
    MemNeeded += (1 << pf.GetBitsPerPixel())*sizeof (RGBQUAD);
  }

  m_pBMI = (BITMAPINFOHEADER*) malloc (MemNeeded);
  // out of memory?
  if (!m_pBMI)
    throw (PLTextException (PL_ERRNO_MEMORY, "Out of memory creating bitmap."));

  // Fill in the header info.
  m_pBMI->biSize = sizeof(BITMAPINFOHEADER);
  m_pBMI->biWidth = Width;
  m_pBMI->biHeight = Height;
  m_pBMI->biPlanes = 1;
  m_pBMI->biBitCount = pf.GetBitsPerPixel();
  m_pBMI->biCompression = BI_RGB;   // No compression
  m_pBMI->biSizeImage = 0;
  m_pBMI->biXPelsPerMeter = 0;
  m_pBMI->biYPelsPerMeter = 0;
  m_pBMI->biClrUsed = 0;           // Always use the whole palette.
  m_pBMI->biClrImportant = 0;

  // Create DIB section in shared memory
  m_hBitmap = CreateDIBSection (NULL, (BITMAPINFO *)m_pBMI,
                                DIB_RGB_COLORS, (void **)&m_pBits, 0, 0l);
  if (!m_hBitmap)
    throw (PLTextException (PL_ERRNO_MEMORY, "Out of memory creating bitmap."));

  // Set color table pointer & pointer to bits.
  initPointers ();

  initLocals (Width, Height, pf);

  PLASSERT_VALID (this);
}
Beispiel #7
0
ThreadPool::ThreadPool(int initThreads, int maxThreads, int lowp, int highp,bool console) {
	this->console = console;
	if (lowp > highp)
		throw "Low Priority should be less than Highest Priority";
	this->initThreads = initThreads;
	this->maxThreads = maxThreads;
	this->lowp = lowp;
	this->highp = highp;
	this->runFlag = false;
	joinComplete = false;
	prioritypooling = true;
	initPointers();
	initializeThreads();
}
Beispiel #8
0
void ThreadPool::init(int initThreads, int maxThreads,bool console)
{
	if(wpool!=NULL)return;
	this->console = console;
	this->lowp = -1;
	this->highp = -1;
	this->initThreads = initThreads;
	this->maxThreads = maxThreads;
	joinComplete = false;
	prioritypooling = false;
	initPointers();
	initializeThreads();
	start();
}
Beispiel #9
0
void PLDIBSection::internalCreate
    ( BITMAPINFOHEADER* pBMI
    )
    // Creates a PLDIBSection from an existing bitmap pointer.
    // Assumes that no memory is allocated before the call.
{
#ifdef MAX_BITMAP_SIZE
	if (GetMemNeeded (pBMI->biWidth, pBMI->biHeight, pBMI->biBitCount)
      > MAX_BITMAP_SIZE)
	  throw PLTextException(PL_ERRDIB_TOO_LARGE, "Bitmap size too large.\n");
#endif

  int MemNeeded = sizeof (BITMAPINFOHEADER);
  if (pBMI->biBitCount < 16)
  { // Color table exists
    MemNeeded += (1 << pBMI->biBitCount)*sizeof (RGBQUAD);
  }

  m_pBMI = (BITMAPINFOHEADER *) malloc (MemNeeded);

  memcpy (m_pBMI, pBMI, MemNeeded);

  // Create DIB section in shared memory
  m_hBitmap = CreateDIBSection (NULL, (BITMAPINFO *)m_pBMI,
                                DIB_RGB_COLORS, (void **)&m_pBits, 0, 0l);
  if (!m_hBitmap)
    throw (PLTextException (PL_ERRNO_MEMORY, "Out of memory creating bitmap."));

  // Set color table pointer & pointer to bits.
  initPointers ();

  PLPixelFormat pf = pixelFormatFromBMI(m_pBMI);

  initLocals (m_pBMI->biWidth, m_pBMI->biHeight, pf);

  PLASSERT_VALID (this);
}
Beispiel #10
0
// Constructor
Functions::Functions()
{
	// Create pointer list
	initPointers();
}
Beispiel #11
0
extern "C" BOOL PASCAL EXPORT StartSimulation(char* strInputFilePath,char* strBestPopRun)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	// normal function body here

	int nReturn = TRUE;
	CString str1, str2, strFilePath;
	
	str1 = strInputFilePath;
	str1.TrimLeft();
	str1.TrimRight();
	
	str2 = strBestPopRun;
	str2.TrimLeft();
	str2.TrimRight();
	
	// initialize progress bar
	CProgressWnd wndProgress(NULL, "SUSTAIN_MODEL", TRUE);

	if(str1.GetLength() < 2)	
		return true;

//////////////////////////////////////////////////////////////////////
//SWMM5 initialize conduit parameters
    initPointers();
    setDefaults();
    // --- create hash tables for fast retrieval of objects by ID names
    createHashTables();
//////////////////////////////////////////////////////////////////////
	
	strFilePath = str1;

	CBMPData bmpData;
	CBMPRunner bmpRunner(&bmpData);

	if (!bmpData.ReadInputFile(strFilePath))
	{
		AfxMessageBox(bmpData.strError);
		nReturn = FALSE;
		goto L001;
	}

	//optional weather data
	if (bmpData.nWeatherFile == 1)
	{
		if (!bmpData.ReadWeatherFile(bmpData.strInputDir + "weather.inp"))
			return FALSE;

		if (!bmpData.MarkWetIntervals(bmpData.startDate,bmpData.endDate))
			return FALSE;
	}

	if (!bmpData.PrepareDataForModel())
	{
		AfxMessageBox(bmpData.strError);
		nReturn = FALSE;
		goto L001;
	}

	// disabled for the first release (under testing)
	// run PreDeveloped scenario for bufferstrip simulation if necessary
//	if (!bmpData.RunVFSMOD(RUN_PREDEV))	 
//	{
//		AfxMessageBox(bmpData.strError);
//		nReturn = FALSE;
//		goto L001;
//	}

	// run PostDeveloped scenario for bufferstrip simulation if necessary
//	if (!bmpData.RunVFSMOD(RUN_POSTDEV))	 
//	{
//		AfxMessageBox(bmpData.strError);
//		nReturn = FALSE;
//		goto L001;
//	}
	
	if (!bmpData.OpenOutputFiles("Init"))// open file for time series 
	{
		AfxMessageBox(bmpData.strError);
		nReturn = FALSE;
		goto L001;
	}
	if (!bmpRunner.OpenOutputFiles("Init", bmpData.nRunOption, RUN_INIT))// open file for evaluation factor
	{
		nReturn = FALSE;
		goto L001;
	}

	bmpRunner.pWndProgress = &wndProgress;

	bmpRunner.RunModel(RUN_INIT);

	if (!bmpData.CloseOutputFiles())	// close file for time series
	{
		nReturn = FALSE;
		goto L001;
	}
	if (!bmpRunner.CloseOutputFiles())	// close file for evaluation factor
	{
		nReturn = FALSE;
		goto L001;
	}

	if (bmpRunner.pWndProgress->Cancelled())
	{
		bmpRunner.pWndProgress->DestroyWindow();
		AfxMessageBox("BMP simulation is cancelled");
		goto L001;
	}

	if (!bmpData.OpenOutputFiles("PreDev"))	// open file for time series
	{
		AfxMessageBox(bmpData.strError);
		nReturn = FALSE;
		goto L001;
	}
	if (!bmpRunner.OpenOutputFiles("PreDev", bmpData.nRunOption, RUN_PREDEV))	// open file for evaluation factor
	{
		nReturn = FALSE;
		goto L001;
	}

	bmpRunner.RunModel(RUN_PREDEV);

	if (!bmpData.CloseOutputFiles())	// close file for time series
	{
		nReturn = FALSE;
		goto L001;
	}
	if (!bmpRunner.CloseOutputFiles())	// close file for evaluation factor
	{
		nReturn = FALSE;
		goto L001;
	}

	if (bmpRunner.pWndProgress->Cancelled())
	{
		bmpRunner.pWndProgress->DestroyWindow();
		AfxMessageBox("BMP simulation is cancelled");
		goto L001;
	}

	if (!bmpData.OpenOutputFiles("PostDev"))// open file for time series
	{
		AfxMessageBox(bmpData.strError);
		nReturn = FALSE;
		goto L001;
	}
	if (!bmpRunner.OpenOutputFiles("PostDev", bmpData.nRunOption, RUN_POSTDEV))// open file for evaluation factor
	{
		nReturn = FALSE;
		goto L001;
	}

	bmpRunner.RunModel(RUN_POSTDEV);

	if (!bmpData.CloseOutputFiles())	// close file for time series
	{
		nReturn = FALSE;
		goto L001;
	}
	if (!bmpRunner.CloseOutputFiles())	// close file for evaluation factor
	{
		nReturn = FALSE;
		goto L001;
	}

	if (bmpRunner.pWndProgress->Cancelled())
	{
		bmpRunner.pWndProgress->DestroyWindow();
		AfxMessageBox("BMP simulation is cancelled");
		goto L001;
	}

	srand((unsigned)time(NULL));   // initialize seed for random number generator

	if (bmpData.nRunOption != OPTION_NO_OPTIMIZATION)
	{
		if (bmpData.nStrategy == STRATEGY_SCATTER_SEARCH)
		{
			// run option MinimizeCost or MaximizeControl
			CBMPOptimizer bmpOptimizer(&bmpRunner);
			
			if (bmpData.nAdjVariable < 5)
			{
				bmpOptimizer.problem.b1 = 5;
				bmpOptimizer.problem.b2 = 5;
			}
			else
			{
				bmpOptimizer.problem.b1 = bmpData.nAdjVariable;
				bmpOptimizer.problem.b2 = bmpData.nAdjVariable;
			}
			bmpOptimizer.problem.PSize = 3*(bmpOptimizer.problem.b1+bmpOptimizer.problem.b2);
			bmpOptimizer.problem.LS = FALSE;

			if (bmpRunner.lInitRunTime != 0)
				bmpOptimizer.nMaxRun = int((bmpData.lfMaxRunTime*3600000)/bmpRunner.lInitRunTime)+1;
			else
				bmpOptimizer.nMaxRun = 1000;
			if (bmpOptimizer.nMaxRun < 2*bmpOptimizer.problem.PSize)
				bmpOptimizer.nMaxRun = 2*bmpOptimizer.problem.PSize;
			bmpOptimizer.nMaxIter = int(bmpOptimizer.nMaxRun / (2*bmpOptimizer.problem.PSize)) + 1;

			bmpRunner.nMaxRun = bmpOptimizer.nMaxRun;

			// run optimization for Minimum Cost or MaximumControl options
			if (bmpData.nRunOption == OPTION_MIMIMIZE_COST ||
				bmpData.nRunOption == OPTION_MAXIMIZE_CONTROL)
			{
				CString	strOutPath = bmpData.strOutputDir + "\\AllSolutions.out";
				bmpOptimizer.m_pAllSolutions = fopen(LPCSTR(strOutPath), "wt");
				if (bmpOptimizer.m_pAllSolutions == NULL)
				{
					nReturn = FALSE;
					goto L001;
				}

				bmpOptimizer.OutputFileHeader("SS - All solutions", bmpOptimizer.m_pAllSolutions);
				bmpOptimizer.nRunCounter = 0;
				bmpOptimizer.InitProblem(bmpData.nAdjVariable, bmpOptimizer.problem.b1, bmpOptimizer.problem.b2, bmpOptimizer.problem.PSize, bmpOptimizer.problem.LS);
				bmpOptimizer.InitRefSet();
				bmpOptimizer.PerformSearch();
				fclose(bmpOptimizer.m_pAllSolutions);
				bmpOptimizer.OutputBestSolutions();

				if (bmpRunner.pWndProgress->Cancelled())
				{
					bmpRunner.pWndProgress->DestroyWindow();
					AfxMessageBox("BMP simulation is cancelled");
					goto L001;
				}
				else
				{
					bmpRunner.pWndProgress->DestroyWindow();
					AfxMessageBox("BMP simulation completed successfully", MB_ICONINFORMATION);
					goto L001;
				}
			}
			// run optimization for TradeOff Curve options
			else if (bmpData.nRunOption == OPTION_TRADE_OFF_CURVE) 
			{
				CString	strOutPath = bmpData.strOutputDir + "\\AllSolutions.out";
				bmpOptimizer.m_pAllSolutions = fopen(LPCSTR(strOutPath), "wt");
				if (bmpOptimizer.m_pAllSolutions == NULL)
				{
					nReturn = FALSE;
					goto L001;
				}

				bmpOptimizer.OutputFileHeader("SS - All solutions", bmpOptimizer.m_pAllSolutions);

				// prepare output file for TradeOff Curve optimization
				strFilePath = bmpRunner.pBMPData->strOutputDir + "\\CECurve_Solutions.out";
				FILE* fp = fopen(LPCSTR(strFilePath), "wt");
				if(fp == NULL)
				{
					AfxMessageBox("Failed in creating output file "+strFilePath, MB_ICONEXCLAMATION);
					nReturn = FALSE;					
					goto L001;
				}
				bmpOptimizer.OutputFileHeaderForTradeOffCurve(fp);
				
				// initialize problem only once
				bmpOptimizer.InitProblem(bmpData.nAdjVariable, bmpOptimizer.problem.b1, bmpOptimizer.problem.b2, bmpOptimizer.problem.PSize, bmpOptimizer.problem.LS);
				
				//update the max. runs
				bmpRunner.nMaxRun *= (bmpData.nTargetBreak + 1);

				// run optimization for the target range
				for (int i=0; i<=bmpData.nTargetBreak; i++)
				{
					POSITION pos, pos1;
					pos = bmpData.routeList.GetHeadPosition();

					while (pos != NULL)
					{
						CBMPSite* pBMPSite = (CBMPSite*) bmpData.routeList.GetNext(pos);
						pos1 = pBMPSite->m_factorList.GetHeadPosition();

						while (pos1 != NULL)
						{
							EVALUATION_FACTOR* pEF = (EVALUATION_FACTOR*) pBMPSite->m_factorList.GetNext(pos1);
							pEF->m_lfTarget = pEF->m_lfUpperTarget - i*(pEF->m_lfUpperTarget-pEF->m_lfLowerTarget)/bmpData.nTargetBreak;
							pEF->m_lfNextTarget = pEF->m_lfTarget - (pEF->m_lfUpperTarget-pEF->m_lfLowerTarget)/bmpData.nTargetBreak;
						}
					}

					bmpOptimizer.nRunCounter = 0;
					if (i == 0)
						bmpOptimizer.InitRefSet();
					else
						bmpOptimizer.ResetRefSet();
					bmpOptimizer.PerformSearch();
					bmpOptimizer.OutputBestSolutionsForTradeOffCurve(i, fp);

					if (bmpRunner.pWndProgress->Cancelled())
					{
						bmpRunner.pWndProgress->DestroyWindow();
						AfxMessageBox("BMP simulation is cancelled");
						fclose(bmpOptimizer.m_pAllSolutions);
						fclose(fp);
						goto L001;
					}
				}

				fclose(bmpOptimizer.m_pAllSolutions);
				fclose(fp);
			}
		}
		else if (bmpData.nStrategy == STRATEGY_GENETIC_ALGORITHM)
		{
			//run the best population scenarios (call from the post-processor spreadsheet)
			if(str2.GetLength() > 0)
			{
				CString strLine, strValue;
				POSITION pos, pos1;
				CBMPSite* pBMPSite;
				EVALUATION_FACTOR* pEF;
				ADJUSTABLE_PARAM* pAP;

				CStringToken strToken(str2);
				int nBestPops = 0;
				while (strToken.HasMoreTokens())
				{
					str1 = strToken.NextToken();
					nBestPops++;
				}

				bmpData.nSolution = nBestPops;

				// prepare output file for TradeOff Curve optimization
				strFilePath = bmpData.strOutputDir + "\\CECurve_Solutions.out";
				FILE* fp = fopen(LPCSTR(strFilePath), "wt");
				if(fp == NULL)
				{
					AfxMessageBox("Failed in creating output file "+strFilePath, MB_ICONEXCLAMATION);
					nReturn = FALSE;					
					goto L001;
				}
					
				bmpData.OutputFileHeaderForTradeOffCurve(fp);
				CStringToken strToken1(str2);
						
				for (int i=0; i<nBestPops; i++)
				{
					//read best population file
					int nBestPopId = atoi((LPCSTR)strToken1.NextToken());
					if (!bmpData.ReadBestPopFile(nBestPopId))
					{
						AfxMessageBox(bmpData.strError);
						nReturn = FALSE;
						goto L001;
					}

					//output time series for the best pop solution
					strValue.Format("BestPop%d", nBestPopId);
					if (!bmpData.OpenOutputFiles(strValue))
					{
						AfxMessageBox(bmpData.strError);
						nReturn = FALSE;
						goto L001;
					}

					//run model
					bmpRunner.RunModel(RUN_OUTPUT);

					//close time series for the best pop solution
					if (!bmpData.CloseOutputFiles())
					{
						AfxMessageBox(bmpData.strError);
						nReturn = FALSE;
						goto L001;
					}

					//output CECurve_Solutions
					double totalCost = 0.0;
					double output1 = 0.0;
					pos = bmpData.routeList.GetHeadPosition();
					while (pos != NULL)
					{
						pBMPSite = (CBMPSite*) bmpData.routeList.GetNext(pos);
						totalCost += pBMPSite->m_lfCost;
					}

					strLine.Format("%d\t%d", i+1, 1);
					strValue.Format("\t%lf", totalCost);
					strLine += strValue;

					//evaluation factors
					pos = bmpData.routeList.GetHeadPosition();
					while (pos != NULL)
					{
						pBMPSite = (CBMPSite*) bmpData.routeList.GetNext(pos);
						pos1 = pBMPSite->m_factorList.GetHeadPosition();
						while (pos1 != NULL)
						{
							pEF = (EVALUATION_FACTOR*) pBMPSite->m_factorList.GetNext(pos1);
							if (pEF->m_nCalcMode == CALC_PERCENT) // if the calculation mode is percentage
							{
								if (pEF->m_lfPostDev == 0.0)
									output1 = pEF->m_lfCurrent;
								else
									output1 = pEF->m_lfCurrent/pEF->m_lfPostDev*100;
							}
							else if (pEF->m_nCalcMode == CALC_VALUE) // if the calculation mode is value
							{
								output1 = pEF->m_lfCurrent;
							}
							else // if the calculation mode is scale
							{
								if (pEF->m_lfPostDev - pEF->m_lfPreDev > 0)
									output1 = (pEF->m_lfCurrent - pEF->m_lfPreDev) / (pEF->m_lfPostDev-pEF->m_lfPreDev);
								else
									output1 = pEF->m_lfCurrent;
							}
							strValue.Format("\t%lf", output1);
							strLine += strValue;
						}
					}

					//adjust parameters
					pos = bmpData.routeList.GetHeadPosition();
					while (pos != NULL)
					{
						pBMPSite = (CBMPSite*) bmpData.routeList.GetNext(pos);
						pos1 = pBMPSite->m_adjustList.GetHeadPosition();
						while (pos1 != NULL)
						{
							pAP = (ADJUSTABLE_PARAM*) pBMPSite->m_adjustList.GetNext(pos1);
							double* pVariable = pBMPSite->GetVariablePointer(pAP->m_strVariable);
							strValue.Format("\t%lf", *pVariable);
							strLine += strValue;
						}
					}

					strLine += "\n";
					fputs(strLine, fp);
					
					if (bmpRunner.pWndProgress->Cancelled())
					{
						bmpRunner.pWndProgress->DestroyWindow();
						AfxMessageBox("BMP simulation is cancelled");
						fclose(fp);
						nReturn = FALSE;
						goto L001;
					}
				}

				bmpRunner.pWndProgress->DestroyWindow();
				AfxMessageBox("BMP simulation is completed", MB_ICONINFORMATION);
				fclose(fp);
				nReturn = TRUE;
				goto L001;
			}		
			else
			{
				CBMPOptimizerGA bmpOptimizerGA(&bmpRunner);

				if (!bmpOptimizerGA.OpenOutputFiles())
				{
					AfxMessageBox(bmpData.strError);
					nReturn = FALSE;
					goto L001;
				}

				if (!bmpOptimizerGA.LoadData())
				{
					nReturn = FALSE;
					goto L001;
				}

				if (!bmpOptimizerGA.ValidateParams())
				{
					AfxMessageBox(bmpData.strError);
					nReturn = FALSE;
					goto L001;
				}

				bmpOptimizerGA.nMaxRun = bmpOptimizerGA.problem.popsize * bmpOptimizerGA.problem.ngen;
				bmpRunner.nMaxRun = bmpOptimizerGA.nMaxRun;

				if (!bmpOptimizerGA.InitProblem())
				{
					nReturn = FALSE;
					goto L001;
				}

				bmpOptimizerGA.PerformSearch();
				bmpOptimizerGA.OutputBestPopulation();
				bmpOptimizerGA.CloseOutputFiles();

				if (bmpRunner.pWndProgress->Cancelled())
				{
					bmpRunner.pWndProgress->DestroyWindow();
					AfxMessageBox("BMP simulation is cancelled");
					nReturn = FALSE;
					goto L001;
				}
			}
		}
	}

	bmpRunner.pWndProgress->DestroyWindow();
	AfxMessageBox("BMP simulation is completed", MB_ICONINFORMATION);

L001:
	//SWMM5 release memory
    deleteHashTables();
	transect_delete();
	for (int j=0; j<bmpData.nBMPC; j++)
	{
		FREE(Link[j].oldQual);
		FREE(Link[j].newQual);
	}
	FREE(Link);
    FREE(Conduit);
	FREE(GAInfil);

	return nReturn;
}
Beispiel #12
0
ThreadPool::ThreadPool()
{
	initPointers();
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
int CSVGrainDataReader::readFile()
{
  int err = 1;
  char buf[kBufferSize];
  m_headerComplete = false;
  std::ifstream in(m_FileName.c_str());

  if (!in.is_open())
  {
    std::cout << "Ang file could not be opened: " << m_FileName << std::endl;
    return -100;
  }

  ::memset(buf, 0, kBufferSize);
  in.getline(buf, kBufferSize);
  if (sscanf(buf, "%lu", &m_NumberOfElements) != 1)
  {
    std::cout << "First Line of file not parsed." << std::endl;
  }
  else
  {
    std::cout << "m_NumberOfElements = " << m_NumberOfElements << std::endl;
  }

  ::memset(buf, 0, kBufferSize);
  in.getline(buf, kBufferSize);
  parseHeaderLine(buf, kBufferSize);

  // Delete any currently existing pointers
  deletePointers();

  initPointers(m_NumberOfElements);

  if (NULL == m_GrainId ||
      NULL == m_Phi1 ||
      NULL == m_Phi ||
      NULL == m_Phi2 ||
      NULL == m_EquivDiam ||
      NULL == m_NumNeighbors ||
      NULL == m_B_Over_A ||
      NULL == m_C_Over_A ||
      m_Omega3 == NULL ||
      m_OutsideBoundingBox == NULL)
  {
    return -1;
  }

  size_t counter = 0;
  for(size_t row = 0; row < m_NumberOfElements && in.eof() == false; ++row)
  {
    in.getline(buf, kBufferSize);
    this->readData(buf, static_cast<int>(row), counter);
    // Read the next line of data
    ++counter;
  }


  if (counter != m_NumberOfElements && in.eof() == true)
  {

    std::cout << "Premature End Of File reached.\n" << m_FileName
              << "\nNumRows=" << m_NumberOfElements
              << "\ncounter=" << counter << " m_NumberOfElements=" << m_NumberOfElements
              << "\nTotal Data Points Read=" << counter << std::endl;
  }

  return err;
}
Beispiel #14
0
So2sdrBandmap::So2sdrBandmap(QStringList args, QWidget *parent) : QMainWindow(parent)
{
    setupUi(this);
    initPointers();
    initVariables();

    // check to see if user directory exists
    initialized = checkUserDirectory();
    settingsFile = userDirectory()+"/so2sdr-bandmap.ini";

    // check for optional command argument giving station config file name
    if (args.size() > 1) {
        settingsFile = args[1].trimmed();
        // Qt doesn't understand that ~/... implies home directory...
        if (settingsFile.left(1)=="~") {
            if (settingsFile.left(2)=="~/") {
                settingsFile=QDir::homePath()+settingsFile.right(settingsFile.size()-1);
            } else {
                // for cases like ~name : no easy way to parse, give up
                QMessageBox msgBox;
                msgBox.setText("Please use the complete path to the settings file.");
                msgBox.setInformativeText(settingsFile);
                msgBox.setStandardButtons(QMessageBox::Ok);
                msgBox.setDefaultButton(QMessageBox::Ok);
                msgBox.exec();
                close();
            }
        }
    }
    QFileInfo fi(settingsFile);
    if (!fi.exists()) {
        QMessageBox msgBox;
        msgBox.setText("The settings file "+settingsFile+" does not exist.");
        msgBox.setInformativeText("Do you want to create it?");
        msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Cancel);
        msgBox.setDefaultButton(QMessageBox::Save);
        if (msgBox.exec()==QMessageBox::Cancel) {
            close();
        }
        firstTime=true;
    }
    settings = new  QSettings(settingsFile,QSettings::IniFormat,this);
    if (settings->status()!=QSettings::NoError) {
        errorBox.showMessage("ERROR: problem starting qsettings");
    }
    // if run the first time with default settings file for second radio,
    // set second radio
    if (firstTime && settingsFile.right(19)=="so2sdr-bandmap2.ini") {
        settings->setValue(s_sdr_nrig,1);
    }
    // restore window size and position
    QString tmp="BandmapWindow";
    settings->beginGroup(tmp);
    resize(settings->value("size", QSize(400, 594)).toSize());
    move(settings->value("pos", QPoint(200, 200)).toPoint());
    settings->endGroup();

    directory.setCurrent(dataDirectory());
    setWindowIcon(QIcon("icon24x24.png"));

    if (settings->value(s_sdr_reverse_scroll,s_sdr_reverse_scroll_def).toBool()) {
        horizontalLayout->removeWidget(CallLabel);
        horizontalLayout->removeWidget(FreqLabel);
        horizontalLayout->removeWidget(display);
        horizontalLayout->insertWidget(0,CallLabel);
        horizontalLayout->insertWidget(1,FreqLabel);
        horizontalLayout->insertWidget(2,display);
    }

    freqPixmap      = QPixmap(FreqLabel->width(), settings->value(s_sdr_fft,s_sdr_fft_def).toInt());
    callPixmap      = QPixmap(CallLabel->width(), settings->value(s_sdr_fft,s_sdr_fft_def).toInt());

    ipAddress= QHostAddress(QHostAddress::LocalHost).toString();
    if (!server.listen(QHostAddress::LocalHost,
                        settings->value(s_sdr_bandmap_tcp_port,s_sdr_bandmap_tcp_port_def).toInt())) {
        qDebug("couldn't start tcp server");
    }
    connect(&server, SIGNAL(newConnection()), this, SLOT(startConnection()));

    setFocusPolicy(Qt::StrongFocus);
    setFocusPolicy(Qt::NoFocus);
    display->setFocusPolicy(Qt::NoFocus);
    CallLabel->setFocusPolicy(Qt::NoFocus);
    FreqLabel->setFocusPolicy(Qt::NoFocus);

    checkBoxMark.setText("Mark");
    checkBoxMark.setToolTip("Enables signal detection.");
    toolBar->setMovable(false);
    QWidget* spacer1 = new QWidget();
    spacer1->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
    toolBar->addWidget(spacer1);
    toolBar->addWidget(&checkBoxMark);
    txLabel.clear();
    txLabel.setText("<font color=#000000>TX");
    toolBar->addWidget(&txLabel);
    slider.setToolTip("Gain for signal detection. To the right is LESS sensitive.");
    slider.setOrientation(Qt::Horizontal);
    connect(&slider,SIGNAL(valueChanged(int)),this,SLOT(updateLevel(int)));
    slider.setFixedWidth(60);
    slider.setMaximum(200);
    slider.setMinimum(0);
    slider.setSingleStep(10);
    slider.setPageStep(50);
    slider.setValue(settings->value(s_sdr_level,s_sdr_level_def).toInt());
    toolBar->addWidget(&slider);
    QWidget* spacer2 = new QWidget();
    spacer2->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
    toolBar->addWidget(spacer2);
    toolBar->addAction("&Help",this,SLOT(showHelp()));

    iqDialog  = new IQBalance(this, Qt::Window);
    iqDialog->clearPlots();
    showToolBar = new QAction("&toolbar",this);
    scaleX1   = new QAction("Zoom x&1", this);
    scaleX2   = new QAction("Zoom x&2", this);
    deleteAct = new QAction("&Delete Call", this);
    checkBoxMark.setChecked(settings->value(s_sdr_peakdetect,s_sdr_peakdetect_def).toBool());

    iqShowData = new QAction("IQ Balance", this);
    connect(iqShowData, SIGNAL(triggered()), this, SLOT(showIQData()));
    connect(&checkBoxMark, SIGNAL(clicked()), this, SLOT(emitParams()));
    connect(deleteAct, SIGNAL(triggered()), this, SLOT(deleteCallMouse()));
    showToolBar->setCheckable(true);
    showToolBar->setChecked(true);
    connect(showToolBar,SIGNAL(triggered(bool)),this,SLOT(setShowToolbar(bool)));
    scaleX1->setCheckable(true);
    scaleX2->setCheckable(true);
    scaleX2->setChecked(false);
    scaleX1->setChecked(true);
    connect(scaleX1, SIGNAL(triggered()), this, SLOT(setScaleX1()));
    connect(scaleX2, SIGNAL(triggered()), this, SLOT(setScaleX2()));
    connect(actionRun,SIGNAL(triggered()),this,SLOT(start()));

    sdrSetup = new SDRDialog(*settings,this);
    connect(actionSetup,SIGNAL(triggered()),sdrSetup,SLOT(show()));
    connect(actionSetup,SIGNAL(triggered()),this,SLOT(disconnectSignals()));
    connect(sdrSetup,SIGNAL(setupErrors(QString)),&errorBox,SLOT(showMessage(QString)));
    connect(sdrSetup,SIGNAL(update()),this,SLOT(setSdrType()));
    connect(sdrSetup,SIGNAL(restartSdr()),this,SLOT(restartSdr()));
    connect(display, SIGNAL(displayMouseQSY(int)), this, SLOT(mouseQSYDelta(int)));
    toolBarHeight = toolBar->height();

    // select type of SDR, create data source sdrSource
    spectrumProcessor = new Spectrum(this,*settings,userDirectory());
    switch ((SdrType)settings->value(s_sdr_type,s_sdr_type_def).toInt()) {
    case soundcard_t:
        sdrSource = new AudioReaderPortAudio(settingsFile);
        break;
    case afedri_t:
        sdrSource = new Afedri(settingsFile);
        break;
    case network_t:
        sdrSource = new NetworkSDR(settingsFile);
        break;
    }
    setSdrType();
    sdrSource->moveToThread(&sdrThread);
    connect(actionSetup,SIGNAL(triggered()),sdrSource,SLOT(stop()),Qt::DirectConnection);
    connect(&sdrThread,SIGNAL(started()),sdrSource,SLOT(initialize()));
    connect(sdrSource,SIGNAL(stopped()),&sdrThread,SLOT(quit()));
    connect(sdrSource,SIGNAL(stopped()),this,SLOT(disconnectSignals()));
    connect(sdrSource,SIGNAL(error(QString)),&errorBox,SLOT(showMessage(QString)));

    connect(spectrumProcessor, SIGNAL(spectrumReady(unsigned char*, unsigned char)), display,
            SLOT(plotSpectrum(unsigned char*, unsigned char)));
    connect(sdrSource, SIGNAL(ready(unsigned char *, unsigned char)),spectrumProcessor,
            SLOT(processData(unsigned char *, unsigned char)),Qt::QueuedConnection);
    connect(iqDialog, SIGNAL(closed(bool)), spectrumProcessor, SLOT(setPlotPoints(bool)));
    connect(iqDialog, SIGNAL(restart()), spectrumProcessor, SLOT(clearIQ()));
    connect(spectrumProcessor, SIGNAL(qsy(int)), this, SLOT(findQsy(int)));
    connect(spectrumProcessor, SIGNAL(clearPlot()), iqDialog, SLOT(clearPlots()));
    connect(spectrumProcessor, SIGNAL(gainPoint(int, double)), iqDialog, SLOT(plotGainPoint(int, double)));
    connect(spectrumProcessor, SIGNAL(phasePoint(int, double)), iqDialog, SLOT(plotPhasePoint(int, double)));
    connect(spectrumProcessor, SIGNAL(gainScale(double, double)), iqDialog, SLOT(setGainScale(double, double)));
    connect(spectrumProcessor, SIGNAL(phaseScale(double, double)), iqDialog, SLOT(setPhaseScale(double, double)));
    connect(spectrumProcessor, SIGNAL(plotGainFunc(double, double, double, double)), iqDialog,
           SLOT(plotGainFunc(double, double, double, double)));
    connect(spectrumProcessor, SIGNAL(plotPhaseFunc(double, double, double, double)), iqDialog,
           SLOT(plotPhaseFunc(double, double, double, double)));

    // vfoPos is the position of the red line indicating center
    vfoPos          = (height()-toolBarHeight)/ 2;
    dragPos         = vfoPos;
    display->setVfoPos(vfoPos);

    makeFreqScaleAbsolute();
    FreqLabel->setPixmap(freqPixmap);
    FreqLabel->update();

    startTimers();
    show();
}