示例#1
0
// Override draw so that when the cell is selected, a drop arrow is shown in the RHS.
BOOL CGridCellCombo::Draw(CDC* pDC, int nRow, int nCol, CRect rect,  BOOL bEraseBkgnd /*=TRUE*/)
{
#ifdef _WIN32_WCE
    return CGridCell::Draw(pDC, nRow, nCol, rect,  bEraseBkgnd);
#else
    // Cell selected?
    //if ( !IsFixed() && IsFocused())
    if (GetGrid()->IsCellEditable(nRow, nCol) && !IsEditing())
    {
        // Get the size of the scroll box
        CSize sizeScroll(GetSystemMetrics(SM_CXVSCROLL), GetSystemMetrics(SM_CYHSCROLL));

        // enough room to draw?
        if (sizeScroll.cy < rect.Width() && sizeScroll.cy < rect.Height())
        {
            // Draw control at RHS of cell
            CRect ScrollRect = rect;
            ScrollRect.left   = rect.right - sizeScroll.cx;
            ScrollRect.bottom = rect.top + sizeScroll.cy;

            // Do the draw 
            pDC->DrawFrameControl(ScrollRect, DFC_SCROLL, DFCS_SCROLLDOWN);

            // Adjust the remaining space in the cell
            rect.right = ScrollRect.left;
        }
    }

    CString strTempText = GetText();
    if (IsEditing())
        SetText(_T(""));

    // drop through and complete the cell drawing using the base class' method
    BOOL bResult = CGridCell::Draw(pDC, nRow, nCol, rect,  bEraseBkgnd);

    if (IsEditing())
        SetText(strTempText);

	return bResult;
#endif
}
示例#2
0
float Map3D_c::GetMaxDepth2(void)
{	// may want to extend for SIGMA_ROMS (all ROMS?) to check the cell depths rather than point depths
	long i,numDepths;
	float depth, maxDepth=0;
	FLOATH depthsHdl = 0;
	TTriGridVel* triGrid = GetGrid();	// don't use refined grid, depths aren't refined
	
	if (!triGrid) return 0; // some error alert, no depth info to check
	
	depthsHdl = triGrid->GetBathymetry();
	if (!depthsHdl) return 0;	// some error alert, no depth info to check
	
	numDepths = _GetHandleSize((Handle)depthsHdl)/sizeof(**depthsHdl);
	for (i=0;i<numDepths;i++)
	{
		depth = INDEXH(depthsHdl,i);
		if (depth > maxDepth) 
			maxDepth = depth;
	}
	return maxDepth;
}
示例#3
0
/* MOPGTextureProperty::OnEvent
 * Called when an event is raised for the control
 *******************************************************************/
bool MOPGTextureProperty::OnEvent(wxPropertyGrid* propgrid, wxWindow* window, wxEvent& e)
{
	// '...' button clicked
	if (e.GetEventType() == wxEVT_BUTTON)
	{
		// Get current texture (if any)
		string tex_current = "";
		if (!IsValueUnspecified())
			tex_current = GetValueAsString();

		// Open map texture browser
		MapTextureBrowser browser(theMapEditor, textype, tex_current, &(theMapEditor->mapEditor().getMap()));
		if (browser.ShowModal() == wxID_OK && browser.getSelectedItem())
			GetGrid()->ChangePropertyValue(this, browser.getSelectedItem()->getName());

		// Refresh text
		RefreshEditor();
	}
	
	return wxStringProperty::OnEvent(propgrid, window, e);
}
//*******************************************************************************
void CBCGPGanttView::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
{
	CBCGPGanttGrid* pWndGridCtrl = GetGrid ();
	if (pWndGridCtrl != NULL)
	{
		ASSERT_VALID (pDC);
		ASSERT (pInfo != NULL);
		ASSERT_VALID (pWndGridCtrl);

		// don't do anything if not fully initialized
		if (!pWndGridCtrl->m_bIsPrinting || pWndGridCtrl->m_pPrintDC == NULL)
		{
			return;
		}

		// Page margins:
		CRect rectMargins = pWndGridCtrl->OnGetPageMargins (pDC, pInfo);
		pInfo->m_rectDraw.DeflateRect (&rectMargins);

		pWndGridCtrl->OnPrint (pDC, pInfo);
	}
}
示例#5
0
/* MOPGThingTypeProperty::OnEvent
 * Called when an event is raised for the control
 *******************************************************************/
bool MOPGThingTypeProperty::OnEvent(wxPropertyGrid* propgrid, wxWindow* window, wxEvent& e)
{
	if (e.GetEventType() == wxEVT_BUTTON)
	{
		// Get type to select initially (if any)
		int init_type = -1;
		if (!IsValueUnspecified())
			init_type = GetValue().GetInteger();

		// Open thing browser
		ThingTypeBrowser browser(theMapEditor, init_type);
		if (browser.ShowModal() == wxID_OK)
		{
			// Set the value if a type was selected
			int type = browser.getSelectedType();
			if (type >= 0)
				GetGrid()->ChangePropertyValue(this, type);
		}
	}

	return wxIntProperty::OnEvent(propgrid, window, e);
}
示例#6
0
void NPC::DisplayWaypointInfo(Client *c) {

	c->Message(0, "Mob is on grid %d, in spawn group %d, on waypoint %d/%d",
		GetGrid(),
		GetSp2(),
		GetCurWp(),
		GetMaxWp() );


	std::vector<wplist>::iterator cur, end;
	cur = Waypoints.begin();
	end = Waypoints.end();
	for(; cur != end; ++cur) {
		c->Message(0,"Waypoint %d: (%.2f,%.2f,%.2f,%.2f) pause %d",
				cur->index,
				cur->x,
				cur->y,
				cur->z,
				cur->heading,
				cur->pause );
	}
}
示例#7
0
int main(int argc, char *argv[])
{
  int myproc, numprocs, j;
  MPI_Comm comm;
  gridT *grid;
  physT *phys;
  propT *prop;

  StartMpi(&argc,&argv,&comm,&myproc,&numprocs);

  ParseFlags(argc,argv,myproc);
  
  if(GRID)
    GetGrid(&grid,myproc,numprocs,comm);
  else
    ReadGrid(&grid,myproc,numprocs,comm);
  

  if(SOLVE) {
    //read parameters in suntans.dat into the solver
    ReadProperties(&prop,grid,myproc);
    // give space and initialize dzf(edge) dzz(center) dzzold(center)
    InitializeVerticalGrid(&grid,myproc);
    AllocatePhysicalVariables(grid,&phys,prop);
    AllocateTransferArrays(&grid,myproc,numprocs,comm);
    OpenFiles(prop,myproc);
    if(RESTART)
      ReadPhysicalVariables(grid,phys,prop,myproc,comm);
    else
      InitializePhysicalVariables(grid,phys,prop,myproc,comm);

    Solve(grid,phys,prop,myproc,numprocs,comm);
    //    FreePhysicalVariables(grid,phys,prop);
    //    FreeTransferArrays(grid,myproc,numprocs,comm);
  }

  EndMpi(&comm);
}
BOOL CGridBtnCellBase::HasCellText()
// returns:  F=auto-size buttons, only
{
    CGridCtrl* pGrid = GetGrid();
    ASSERT( pGrid);

    CRect RectCell;
    if( !pGrid->GetCellRect(m_iRow,
                            m_iCol,
                            &RectCell) )
        return FALSE;

    // rather than see if there is text assigned, check if any
    //  space allocated for text
    CRect RectText( RectCell);
    if( !GetTextRect( &RectText) ) // i/o:  i=dims of cell rect; o=dims of text rect
        return FALSE;

    if( RectText.Width() > 0 )
        return TRUE;

    return FALSE;
}
示例#9
0
BOOL CGridCell::Edit(int nRow, int nCol, CRect rect, CPoint /* point */, UINT nID, UINT nChar)
{
    if ( m_bEditing )
	{      
        if (m_pEditWnd)
		    m_pEditWnd->SendMessage ( WM_CHAR, nChar );    
    }  
	else  
	{   
		DWORD dwStyle = ES_LEFT;
		if (GetFormat() & DT_RIGHT) 
			dwStyle = ES_RIGHT;
		else if (GetFormat() & DT_CENTER) 
			dwStyle = ES_CENTER;
		
		m_bEditing = TRUE;
		
		// InPlaceEdit auto-deletes itself
		CGridCtrl* pGrid = GetGrid();
		m_pEditWnd = new CInPlaceEdit(pGrid, rect, dwStyle, nID, nRow, nCol, GetText(), nChar);
    }
    return TRUE;
}
示例#10
0
double Map3D_c::DepthAtCentroid(long triNum)
{
	float depth1,depth2,depth3;
	double depthAtPoint;	
	long ptIndex1,ptIndex2,ptIndex3;
	FLOATH depthsHdl = 0;
	TTriGridVel* triGrid = GetGrid();	
	
	TopologyHdl topH ;
	
	//NetCDFMover *mover = (NetCDFMover*)(model->GetMover(TYPE_NETCDFMOVER));
	//TCurrentMover* mover = Get3DCurrentMover();
	
	//if (mover && mover->fVar.gridType==SIGMA_ROMS)
	/*if (mover && mover->IAm(TYPE_NETCDFMOVERCURV) && ((NetCDFMoverCurv*)mover)->fVar.gridType==SIGMA_ROMS)
		return (double)((NetCDFMoverCurv*)mover)->GetTotalDepthFromTriIndex(triNum);*/
	
	if (triNum < 0) return -1;
	if (!triGrid) return -1; // some error alert, no depth info to check
	
	topH = triGrid -> GetTopologyHdl();
	if (!topH) return -1;
	
	ptIndex1 = (*topH)[triNum].vertex1;
	ptIndex2 = (*topH)[triNum].vertex2;
	ptIndex3 = (*topH)[triNum].vertex3;
	
	depthsHdl = triGrid->GetDepths();
	if (!depthsHdl) return -1;	// some error alert, no depth info to check
	
	depth1 = (*depthsHdl)[ptIndex1];
	depth2 = (*depthsHdl)[ptIndex2];
	depth3 = (*depthsHdl)[ptIndex3];
	depthAtPoint = (depth1 + depth2 + depth3) / 3.;
	
	return depthAtPoint;
}
示例#11
0
void CGridBtnCellCombo::OnClick( CPoint PointCellRelative)
{
    // immediately edit if user clicked on scroll down button picture

    int iCtlHit = RelPointInCtl( PointCellRelative);  // Relative point coords
    // returns:  Index of control that this point is within bounds of or -1 if no control matches

    BOOL bHitScrollDown = FALSE;
    if( iCtlHit >= 0)
    {
        // if user clicked on scroll down button picture, then show
        //  the drop-down, too

        UINT uiType = GetDrawCtlType( iCtlHit);
        UINT uiState = GetDrawCtlState( iCtlHit);

        bHitScrollDown =    ( uiType == DFC_SCROLL)
                            && uiState & DFCS_SCROLLDOWN;
    }
    if( bHitScrollDown)
    {
        // invoke the edit, now -- similar to CGridCtl::OnEditCell() logic
        CGridCtrl* pGrid = GetGrid();
        ASSERT( pGrid != NULL);

        CRect rect;
        if (!pGrid->GetCellRect( m_iRow, m_iCol, rect))
            return;

        SendMessageToParent(m_iRow, m_iCol, GVN_BEGINLABELEDIT);

        Edit( m_iRow, m_iCol, rect, PointCellRelative, IDC_INPLACE_CONTROL, VK_LBUTTON);
        return;
    }

    CGridBtnCell::OnClick( PointCellRelative);
}
示例#12
0
nsSize
nsGridRowGroupLayout::GetMinSize(nsIBox* aBox, nsBoxLayoutState& aState)
{
  nsSize minSize = nsGridRowLayout::GetMinSize(aBox, aState); 

  PRInt32 index = 0;
  nsGrid* grid = GetGrid(aBox, &index);

  if (grid) 
  {
    // make sure we add in extra columns sizes as well
    bool isHorizontal = IsHorizontal(aBox);
    PRInt32 extraColumns = grid->GetExtraColumnCount(isHorizontal);
    PRInt32 start = grid->GetColumnCount(isHorizontal) - grid->GetExtraColumnCount(isHorizontal);
    for (PRInt32 i=0; i < extraColumns; i++)
    {
      nscoord min = 
        grid->GetMinRowHeight(aState, i+start, !isHorizontal); // GetMinColumnWidth
      AddWidth(minSize, min, isHorizontal);
    }
  }

  return minSize;
}
//*******************************************************************************
void CBCGPGanttView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo) 
{
	CBCGPGanttGrid* pWndGridCtrl = GetGrid ();
	if (pWndGridCtrl != NULL)
	{
		ASSERT_VALID (pWndGridCtrl);

		ASSERT_VALID (pDC);
		ASSERT (pInfo != NULL);

		int nFirstItem = 0;										// By default print all grid items
		int nLastItem  = max(pWndGridCtrl->GetTotalItems () - 1, 0);	// from first row to the last
		pWndGridCtrl->OnPreparePrintPages (pInfo, nFirstItem, nLastItem);

		ASSERT (pInfo == pWndGridCtrl->m_PrintParams.m_pPrintInfo);
		ASSERT (pInfo->m_lpUserData != NULL);

		pWndGridCtrl->m_bIsPrinting = TRUE;
		pWndGridCtrl->m_pPrintDC = pDC;

		pWndGridCtrl->OnBeginPrinting (pDC, pInfo);

		// The printable area has not been initialized. Initialize it.
		pInfo->m_rectDraw.SetRect (0, 0,
								pDC->GetDeviceCaps(HORZRES), 
								pDC->GetDeviceCaps(VERTRES));

		// Page margins:
		CRect rectMargins = pWndGridCtrl->OnGetPageMargins (pDC, pInfo);
		pInfo->m_rectDraw.DeflateRect (&rectMargins);

		// Specify pages count:
		int nPagesCount = pWndGridCtrl->OnCalcPrintPages (pDC, pInfo);
		pInfo->SetMaxPage (nPagesCount);
	}
}
示例#14
0
/*****************************************************************************
May mean end of a button click sequence or to edit text

*****************************************************************************/
BOOL CGridBtnCellBase::Edit(int nRow, int nCol, CRect rect, CPoint point, UINT nID, UINT nChar)
{
    ASSERT( m_pBtnDataBase != NULL);

    if( ProcessCtlClick(WM_LBUTTONUP,       // Command that invoked.  e.g. WM_LBUTTONDOWN
                        point) ) // point to check for hit
    {
        SendMessageToParent( m_iRow, m_iCol, NM_CLICK); // tell parent about it
        return FALSE;   // clicked a control rather than edited a value
    }

    const int iCtlNbr = GetDrawCtlNbr();
    if( iCtlNbr > 0 )
    {
        // if there's at least one left-aligned control and user pressed
        //  space bar, activate that control
        if( GetDrawCtlAlign( 0) == CTL_ALIGN_LEFT
            || iCtlNbr == 1)
        {
            if( nChar == ' ' )
            {
                // user hit space bar -- just like clicking a button
                ClickedCellCtl( WM_LBUTTONDOWN,   // Command that invoked.  e.g. WM_LBUTTONDOWN
                                0);    // zero-based index of image to draw
                Sleep( 200);
                ClickedCellCtl( WM_LBUTTONUP,   // Command that invoked.  e.g. WM_LBUTTONDOWN
                                0);    // zero-based index of image to draw

                SendMessageToParent( m_iRow, m_iCol, NM_CLICK); // tell parent about it

                return FALSE;   // clicked a control rather than edited a value
            }
        }
    }

    // if no string text to edit, then typing a character may invoke a button
    if( HasCellText() )
    {
        DWORD dwStyle = ES_LEFT;
        if (GetFormat() & DT_RIGHT)
            dwStyle = ES_RIGHT;
        else if (GetFormat() & DT_CENTER)
            dwStyle = ES_CENTER;

        m_ucEditing = TRUE;

        // InPlaceEdit auto-deletes itself
        CGridCtrl* pGrid = GetGrid();
        CWnd* pWnd = new CInPlaceEdit(pGrid, rect, dwStyle, nID, nRow, nCol, GetText(), nChar);
        m_pBtnDataBase->SetEditWnd( pWnd);
    }
    else
    {
        // since no text to edit, maybe press a button -- check for hot keys
        int iCtl = HotKeyBtnMatch( (char)nChar); // hot key character
        if( iCtl >= 0 )
        {
            // returns:  index of button or -1 if no hot key matches
            ClickedCellCtl( WM_LBUTTONDOWN,   // Command that invoked.  e.g. WM_LBUTTONDOWN
                            iCtl);    // zero-based index of image to draw
            Sleep( 200);
            ClickedCellCtl( WM_LBUTTONUP,   // Command that invoked.  e.g. WM_LBUTTONDOWN
                            iCtl);    // zero-based index of image to draw

            SendMessageToParent( m_iRow, m_iCol, NM_CLICK); // tell parent about it
            return FALSE;   // clicked a control rather than edited a value
        }
    }

    return TRUE;
}
示例#15
0
BOOL CGridBtnCellBase::DrawBtnCell(CDC* pDC, int /* nRow */, int /* nCol */, CRect* prect,
    BOOL /* bEraseBkgnd */)
{
    CGridCtrl* pGrid = GetGrid();

    if (!pGrid || !pDC)
        return FALSE;

    if( prect->Width() <= 0
        || prect->Height() <= 0)  // prevents imagelist item from drawing even
        return FALSE;           //  though cell is hidden

    int nSavedDC = pDC->SaveDC();

    // draw any button images
    ASSERT( MAX_NBR_CTLS_INCELL > GetDrawCtlNbrMax() ); // whoa!
    const int iCtlNbr = GetDrawCtlNbr();
    CRect RectAry[ MAX_NBR_CTLS_INCELL];

    if( iCtlNbr > 0)
    {
        if( GetState() & GVIS_SELECTED
            || GetState() & GVIS_DROPHILITED )
        {
            // draw the rectangle around the grid --
            //  we may be filling cells with controls
            pDC->SelectStockObject(BLACK_PEN);
            pDC->SelectStockObject(NULL_BRUSH);
            pDC->Rectangle(*prect);
        }

        pDC->SetBkMode(TRANSPARENT);
        prect->DeflateRect( GetMargin(), 0);


        CFont* pOldFont = pDC->SelectObject(GetFontObject());

        if( CalcDrawCtlRects(   RectAry,    // returns:  CRects with coordinates
                                            //  last entry has optional leftover rect
                                            //  available for text, etc.
                                MAX_NBR_CTLS_INCELL,// nbr of Rects in above array
                                *prect) )     // cell rectangle to work with
        {
            for( int i1=0; i1 < iCtlNbr; i1++)
            {
                UINT uiType = GetDrawCtlType( i1);
                UINT uiState = GetDrawCtlState( i1);

                pDC->DrawFrameControl(  RectAry[ i1],
                                        uiType,
                                        uiState);

                // if button has text, draw it, too
                const char* pszBtnText = GetDrawCtlBtnText( i1);
                if( pszBtnText != NULL)
                {
                    COLORREF ColorCurrent = pDC->GetTextColor();

                    if( uiState & DFCS_INACTIVE)
                    {
                        // button is grayed-out

                        // draw the text so that it matches MS's look
                        RectAry[ i1].OffsetRect( 1, 1);
                        pDC->SetTextColor( RGB( 255,255,255) );
                        pDC->DrawText(  pszBtnText,
                                        -1,
                                        RectAry[ i1],
                                        DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS);

                        RectAry[ i1].OffsetRect( -1, -1);
                        pDC->SetTextColor( ::GetSysColor(COLOR_GRAYTEXT));
                    }
                    else
                    {
                        pDC->SetTextColor( ::GetSysColor(COLOR_BTNTEXT));
                    }

                    pDC->DrawText(  pszBtnText,
                                    -1,
                                    RectAry[ i1],
                                    DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS);
                    pDC->SetTextColor( ColorCurrent);
                }
            }
            // allowable text area has shrunk up
            *prect = RectAry[ iCtlNbr];
        }

        pDC->SelectObject(pOldFont);

        // maybe there's nothing left to draw
        if( prect->Width() <= 0)
        {
            pDC->RestoreDC(nSavedDC);
            return TRUE;
        }
    }
    pDC->RestoreDC(nSavedDC);
    return TRUE;

}
// This hack allows you to determine the height that a cell should be in order to display
// stuff properly in the given width.
CSize CGridCellMultiLine::GetTextExtentEx(int width, LPCTSTR szText, CDC* pDC /*= NULL*/)
{
	CGridCtrl* pGrid = GetGrid();
	ASSERT(pGrid);
	
	BOOL bReleaseDC = FALSE;
	if (pDC == NULL)
	{
		pDC = pGrid->GetDC();
		if (!pDC) 
		{
			CGridDefaultCell* pDefCell = (CGridDefaultCell*) GetDefaultCell();
			ASSERT(pDefCell);
			return CSize(pDefCell->GetWidth(), pDefCell->GetHeight());
		}
		bReleaseDC = TRUE;
	}
	
	CFont *pOldFont = NULL,
	*pFont = GetFontObject();
	if (pFont)
		pOldFont = pDC->SelectObject(pFont);
	
	CSize size;
	int nFormat = GetFormat();
	TEXTMETRIC tm;
	pDC->GetTextMetrics(&tm);

	int textWidth = width - (4*GetMargin ());

	// corrects the bug if resizing column gives a text width smaller than (4*Getmargin())
	if (textWidth <= 0) 
	{
		textWidth = 1;
	}
	
	// If the cell is a multiline cell, then use the width of the cell
	// to get the height
	if ((nFormat & DT_WORDBREAK) && !(nFormat & DT_SINGLELINE))
	{
		CRect rect;
		rect.SetRect(0, 0, textWidth, 0);
		pDC->DrawText(szText, -1, rect, nFormat | DT_CALCRECT);

		size.cx = rect.Width ();
		size.cy = rect.Height ();
	}
	else
		size = pDC->GetTextExtent(szText, _tcslen(szText));
	
	size.cx += (tm.tmOverhang);
	
	if (pOldFont)
		pDC->SelectObject(pOldFont);
	
	size += CSize(4*GetMargin(), 2*GetMargin());
	
	// Kludge for vertical text
	LOGFONT *pLF = GetFont();
	if (pLF->lfEscapement == 900 || pLF->lfEscapement == -900)
	{
		int nTemp = size.cx;
		size.cx = size.cy;
		size.cy = nTemp;
		size += CSize(0, 4*GetMargin());
	}
	
	if (bReleaseDC)
		pGrid->ReleaseDC(pDC);
	
	return size;
}
示例#17
0
static int Integrate(This *t, real *integral, real *error, real *prob)
{
  bin_t *bins;
  count dim, comp;
  int fail;

  StateDecl;
  csize_t statesize = sizeof(State) +
    NCOMP*sizeof(Cumulants) + NDIM*sizeof(Grid);
  Sized(State, state, statesize);
  Cumulants *c, *C = state->cumul + t->ncomp;
  Grid *state_grid = (Grid *)C;
  Array(Grid, margsum, NCOMP, NDIM);
  Vector(char, out, 128*NCOMP + 256);

  if( VERBOSE > 1 ) {
    sprintf(out, "Vegas input parameters:\n"
      "  ndim " COUNT "\n  ncomp " COUNT "\n"
      "  epsrel " REAL "\n  epsabs " REAL "\n"
      "  flags %d\n  seed %d\n"
      "  mineval " NUMBER "\n  maxeval " NUMBER "\n"
      "  nstart " NUMBER "\n  nincrease " NUMBER "\n"
      "  nbatch " NUMBER "\n  gridno %d\n"
      "  statefile \"%s\"",
      t->ndim, t->ncomp,
      t->epsrel, t->epsabs,
      t->flags, t->seed,
      t->mineval, t->maxeval,
      t->nstart, t->nincrease, t->nbatch,
      t->gridno, t->statefile);
    Print(out);
  }

  if( BadComponent(t) ) return -2;
  if( BadDimension(t) ) return -1;

  FrameAlloc(t, ShmRm(t));
  ForkCores(t);
  Alloc(bins, t->nbatch*t->ndim);

  if( (fail = setjmp(t->abort)) ) goto abort;

  IniRandom(t);

  StateSetup(t);

  if( StateReadTest(t) ) {
    StateReadOpen(t, fd) {
      if( read(fd, state, statesize) != statesize ||
          state->signature != StateSignature(t, 1) ) break;
    } StateReadClose(t, fd);
    t->neval = state->neval;
    t->rng.skiprandom(t, t->neval);
  }

  if( ini ) {
    state->niter = 0;
    state->nsamples = t->nstart;
    FClear(state->cumul);
    GetGrid(t, state_grid);
    t->neval = 0;
  }

  /* main iteration loop */
  for( ; ; ) {
    number nsamples = state->nsamples;
    creal jacobian = 1./nsamples;

    FClear(margsum);

    for( ; nsamples > 0; nsamples -= t->nbatch ) {
      cnumber n = IMin(t->nbatch, nsamples);
      real *w = t->frame;
      real *x = w + n;
      real *f = x + n*t->ndim;
      real *lastf = f + n*t->ncomp;
      bin_t *bin = bins;

      while( x < f ) {
        real weight = jacobian;

        t->rng.getrandom(t, x);

        for( dim = 0; dim < t->ndim; ++dim ) {
          creal pos = *x*NBINS;
          ccount ipos = (count)pos;
          creal prev = (ipos == 0) ? 0 : state_grid[dim][ipos - 1];
          creal diff = state_grid[dim][ipos] - prev; 
          *x++ = prev + (pos - ipos)*diff;
          *bin++ = ipos;
          weight *= diff*NBINS;
        }

        *w++ = weight;
      }

      DoSample(t, n, w, f, t->frame, state->niter + 1);

      bin = bins;
      w = t->frame;

      while( f < lastf ) {
        creal weight = *w++;
        Grid *m = &margsum[0][0];

        for( c = state->cumul; c < C; ++c ) {
          real wfun = weight*(*f++);
          if( wfun ) {
            c->sum += wfun;
            c->sqsum += wfun *= wfun;
            for( dim = 0; dim < t->ndim; ++dim )
              m[dim][bin[dim]] += wfun;
          }
          m += t->ndim;
        }

        bin += t->ndim;
      }
    }

    fail = 0;

    /* compute the integral and error values */

    for( c = state->cumul; c < C; ++c ) {
      real w = Weight(c->sum, c->sqsum, state->nsamples);
      real sigsq = 1/(c->weightsum += w);
      real avg = sigsq*(c->avgsum += w*c->sum);

      c->avg = LAST ? (sigsq = 1/w, c->sum) : avg;
      c->err = sqrt(sigsq);
      fail |= (c->err > MaxErr(c->avg));

      if( state->niter == 0 ) c->guess = c->sum;
      else {
        c->chisum += w *= c->sum - c->guess;
        c->chisqsum += w*c->sum;
      }
      c->chisq = c->chisqsum - avg*c->chisum;

      c->sum = c->sqsum = 0;
    }

    if( VERBOSE ) {
      char *oe = out + sprintf(out, "\n"
        "Iteration " COUNT ":  " NUMBER " integrand evaluations so far",
        state->niter + 1, t->neval);
      for( c = state->cumul, comp = 0; c < C; ++c )
        oe += sprintf(oe, "\n[" COUNT "] "
          REAL " +- " REAL "  \tchisq " REAL " (" COUNT " df)",
          ++comp, c->avg, c->err, c->chisq, state->niter);
      Print(out);
    }

    if( fail == 0 && t->neval >= t->mineval ) break;

    if( t->neval >= t->maxeval && !StateWriteTest(t) ) break;

    if( t->ncomp == 1 )
      for( dim = 0; dim < t->ndim; ++dim )
        RefineGrid(t, state_grid[dim], margsum[0][dim]);
    else {
      for( dim = 0; dim < t->ndim; ++dim ) {
        Grid wmargsum;
        Zap(wmargsum);
        for( comp = 0; comp < t->ncomp; ++comp ) {
          real w = state->cumul[comp].avg;
          if( w != 0 ) {
            creal *m = margsum[comp][dim];
            count bin;
            w = 1/Sq(w);
            for( bin = 0; bin < NBINS; ++bin )
              wmargsum[bin] += w*m[bin];
          }
        }
        RefineGrid(t, state_grid[dim], wmargsum);
      }
    }

    ++state->niter;
    state->nsamples += t->nincrease;

    if( StateWriteTest(t) ) {
      state->signature = StateSignature(t, 1);
      state->neval = t->neval;
      StateWriteOpen(t, fd) {
        StateWrite(fd, state, statesize);
      } StateWriteClose(t, fd);
      if( t->neval >= t->maxeval ) break;
    }
  }
示例#18
0
void LevelSetOperator::IntegrateRungeKutta(float dt)
{
	/*
		TVD RK
	*/
	/*
	//Spara värdet för n samt beräkna n+1
  LevelSetGrid grid = GetGrid();
  LevelSetGrid gridOldPhi(grid.GetDimX(),grid.GetDimY(),grid.GetDimZ()) ;
  LevelSetGrid::Iterator iter = GetGrid().BeginNarrowBand();
  LevelSetGrid::Iterator iend = GetGrid().EndNarrowBand();
  while (iter != iend) {
    unsigned int i = iter.GetI();
    unsigned int j = iter.GetJ();
    unsigned int k = iter.GetK();

    // Compute rate of change
    float ddt = Evaluate(i,j,k);//Beräkna derivatan i n
	gridOldPhi.SetValue(i,j,k,GetGrid().GetValue(i,j,k));
	float phi_new = GetGrid().GetValue(i,j,k)  + ddt*dt;
    // Compute the next time step and store it in the grid
    grid.SetValue(i,j,k,phi_new);
    iter++;
  }
  GetGrid() = grid;

  //Beräkna nytt n+1 via n och n+2
  iter = GetGrid().BeginNarrowBand();
  iend = GetGrid().EndNarrowBand();
  while (iter != iend) {
    unsigned int i = iter.GetI();
    unsigned int j = iter.GetJ();
    unsigned int k = iter.GetK();

    // Compute rate of change
    float ddt = Evaluate(i,j,k); //Beräkna derivatan i n+1

	float old_phi = gridOldPhi.GetValue(i,j,k);
	float phi_new = 0.5*(old_phi +  (GetGrid().GetValue(i,j,k) + ddt*dt));//0.5(n + (n+2)) = n+1
    // Compute the next time step and store it in the grid
    grid.SetValue(i,j,k,phi_new);
    iter++;
  }
  GetGrid() = grid;*/
	/*
	//K1
	LevelSetGrid grid = GetGrid();
	LevelSetGrid y(grid.GetDimX(),grid.GetDimY(),grid.GetDimZ()) ;
	LevelSetGrid k1(grid.GetDimX(),grid.GetDimY(),grid.GetDimZ()) ;
	LevelSetGrid::Iterator iter = GetGrid().BeginNarrowBand();
	LevelSetGrid::Iterator iend = GetGrid().EndNarrowBand();
	while (iter != iend) 
	{
		unsigned int i = iter.GetI();
		unsigned int j = iter.GetJ();
		unsigned int k = iter.GetK();

		// Compute rate of change
		float ddt = Evaluate(i,j,k);//Beräkna derivatan i k1
		y.SetValue(i,j,k,GetGrid().GetValue(i,j,k));
		k1.SetValue(i,j,k,ddt*dt);
		// Compute the next time step and store it in the grid
		grid.SetValue(i,j,k, y.GetValue(i,j,k) + (1.0/2.0)*k1.GetValue(i,j,k));
		iter++;
	}
	GetGrid() = grid;

	//K2
	LevelSetGrid k2(grid.GetDimX(),grid.GetDimY(),grid.GetDimZ()) ;
	 iter = GetGrid().BeginNarrowBand();
	 iend = GetGrid().EndNarrowBand();
	while (iter != iend) 
	{
		unsigned int i = iter.GetI();
		unsigned int j = iter.GetJ();
		unsigned int k = iter.GetK();

		// Compute rate of change
		float ddt = Evaluate(i,j,k);//Beräkna derivatan i k2
		k2.SetValue(i,j,k,ddt*dt);
		// Compute the next time step and store it in the grid
		grid.SetValue(i,j,k, y.GetValue(i,j,k) + (1.0/2.0)*k2.GetValue(i,j,k));
		iter++;
	}
	GetGrid() = grid;

	//K3
	LevelSetGrid k3(grid.GetDimX(),grid.GetDimY(),grid.GetDimZ()) ;
	 iter = GetGrid().BeginNarrowBand();
	 iend = GetGrid().EndNarrowBand();
	while (iter != iend) 
	{
		unsigned int i = iter.GetI();
		unsigned int j = iter.GetJ();
		unsigned int k = iter.GetK();

		// Compute rate of change
		float ddt = Evaluate(i,j,k);//Beräkna derivatan i k3
		k3.SetValue(i,j,k,ddt*dt);
		// Compute the next time step and store it in the grid
		grid.SetValue(i,j,k, y.GetValue(i,j,k) + k3.GetValue(i,j,k));
		iter++;
	}
	GetGrid() = grid;

	//K4
	LevelSetGrid k4(grid.GetDimX(),grid.GetDimY(),grid.GetDimZ()) ;
	 iter = GetGrid().BeginNarrowBand();
	 iend = GetGrid().EndNarrowBand();
	while (iter != iend) 
	{
		unsigned int i = iter.GetI();
		unsigned int j = iter.GetJ();
		unsigned int k = iter.GetK();

		// Compute rate of change
		float ddt = Evaluate(i,j,k);//Beräkna derivatan i k3
		k4.SetValue(i,j,k,ddt*dt);
		iter++;
	}
	GetGrid() = grid;

  //Beräkna nytt n+1 via n och n+2
  iter = GetGrid().BeginNarrowBand();
  iend = GetGrid().EndNarrowBand();
  while (iter != iend) {
    unsigned int i = iter.GetI();
    unsigned int j = iter.GetJ();
    unsigned int k = iter.GetK();
	
	float yn =   y.GetValue(i,j,k);
	float k1n =  k1.GetValue(i,j,k);
	float k2n =  k2.GetValue(i,j,k);
	float k3n =  k3.GetValue(i,j,k);
	float k4n =  k4.GetValue(i,j,k);

	float new_y = yn + (1.0/6.0)*(k1n+k4n) + (1.0/3.0)*(k2n + k3n);

    grid.SetValue(i,j,k,new_y);
    iter++;
  }
  GetGrid() = grid;*/

	LevelSetGrid grid = GetGrid();
	LevelSetGrid n(grid.GetDimX(),grid.GetDimY(),grid.GetDimZ()) ;
	LevelSetGrid::Iterator iter = GetGrid().BeginNarrowBand();
	LevelSetGrid::Iterator iend = GetGrid().EndNarrowBand();
	while (iter != iend) {
		unsigned int i = iter.GetI();
		unsigned int j = iter.GetJ();
		unsigned int k = iter.GetK();

		// Compute rate of change
		float ddt = Evaluate(i,j,k);//Beräkna derivatan i n
		n.SetValue(i,j,k,GetGrid().GetValue(i,j,k));
		float n1 = GetGrid().GetValue(i,j,k)  + ddt*dt;
		// Compute the next time step and store it in the grid
		grid.SetValue(i,j,k,n1);
		iter++;
	}
	GetGrid() = grid;

	iter = GetGrid().BeginNarrowBand();
	iend = GetGrid().EndNarrowBand();
	while (iter != iend) {
		unsigned int i = iter.GetI();
		unsigned int j = iter.GetJ();
		unsigned int k = iter.GetK();

		// Compute rate of change
		float ddt = Evaluate(i,j,k);//Beräkna derivatan i n

		float n2 = GetGrid().GetValue(i,j,k)  + ddt*dt;
		float n0 = n.GetValue(i,j,k);
		float n1 = (n0+n2)/2.0;
		// Compute the next time step and store it in the grid
		grid.SetValue(i,j,k,n1);
		iter++;
	}
	GetGrid() = grid;

	iter = GetGrid().BeginNarrowBand();
	iend = GetGrid().EndNarrowBand();
	while (iter != iend) {
		unsigned int i = iter.GetI();
		unsigned int j = iter.GetJ();
		unsigned int k = iter.GetK();

		// Compute rate of change
		float ddt = Evaluate(i,j,k);//Beräkna derivatan i n
		float n2 = GetGrid().GetValue(i,j,k)  + ddt*dt;
		// Compute the next time step and store it in the grid
		grid.SetValue(i,j,k,n2);
		iter++;
	}
	GetGrid() = grid;

	iter = GetGrid().BeginNarrowBand();
	iend = GetGrid().EndNarrowBand();
	while (iter != iend) {
		unsigned int i = iter.GetI();
		unsigned int j = iter.GetJ();
		unsigned int k = iter.GetK();

		// Compute rate of change
		float ddt = Evaluate(i,j,k);//Beräkna derivatan i n
		float n0 = n.GetValue(i,j,k);
		float n2 = GetGrid().GetValue(i,j,k)  + ddt*dt;
		// Compute the next time step and store it in the grid
		float n12 = 3.0/4.0*n0 + 1.0/4.0*n2;
		grid.SetValue(i,j,k,n12);
		iter++;
	}
	GetGrid() = grid;

	iter = GetGrid().BeginNarrowBand();
	iend = GetGrid().EndNarrowBand();
	while (iter != iend) {
		unsigned int i = iter.GetI();
		unsigned int j = iter.GetJ();
		unsigned int k = iter.GetK();

		// Compute rate of change
		float ddt = Evaluate(i,j,k);//Beräkna derivatan i n
		float n0 = n.GetValue(i,j,k);
		float n32 = GetGrid().GetValue(i,j,k)  + ddt*dt;
		// Compute the next time step and store it in the grid
		float n1 = 1.0/3.0*n0 + 2.0/3.0*n32;
		grid.SetValue(i,j,k,n1);
		iter++;
	}
	GetGrid() = grid;
}
/*****************************************************************************
Allows Tree + Btn object to call drawing member

*****************************************************************************/
BOOL CGridTreeCellBase::DrawTreeCell(CDC* pDC, int nRow, int nCol, CRect* prect,
    BOOL /* bEraseBkgnd */)
{
    ASSERT( m_pTreeColumn != NULL);

    if( !m_pTreeColumn->GetAllowDraw())
        return FALSE;

    CGridCtrl* pGrid = GetGrid();

    if (!pGrid || !pDC)
        return FALSE;

    if( m_pTreeColumn->GetFixedRowCount() != pGrid->GetFixedRowCount()
        || m_pTreeColumn->GetRowCount() > pGrid->GetRowCount() )
    {
        ASSERT( FALSE); // if ASSERT here, this means that you a tree in a column
                        //  but you called CGridCtrl::SetFixedRowCount() or
                        //  or CGridCtrl::SetRowCount() directly.  You can't do this.
                        //  To change the layout of rows when you are using the tree,
                        //  you must call CTreeColumn::Setup().
        return FALSE;
    }

    if( prect->Width() <= 0
        || prect->Height() <= 0)  // prevents imagelist item from drawing even
        return FALSE;           //  though cell is hidden

    // tree drawing graphic logic begins here

    int nSavedDC = pDC->SaveDC();

    if( nCol == m_pTreeColumn->GetColumnWithTree())
    {
        // this column has a tree

        // move text over to allow for level indentation
        if( IsViewable() )
        {
            // if row is showing, draw the tree graphic
            if( m_pTreeColumn->GetTreeLines())
            {
                TreeDrawGraphic(    pDC,      // current CDC
                                    *prect);    // coordinates of bounding cell rectangle
            }
            else if( m_pTreeColumn->GetTreeUsesImages())
            {
                TREE_IMAGE TreeImage = TREE_IMAGE_DOCUMENT;

                // is it not the very last row?
                if( nRow + m_pTreeColumn->GetFixedRowCount() < m_pTreeColumn->GetRowCount())
                {
                    // is it a plus or minus?
                    BOOL bIsPlus;
                    BOOL bIsMinus;
                    BOOL bIsLastLeaf;

                    if( m_pTreeColumn->TreeCellHasPlusMinus(   nRow,        // row of Cell to check
                                                &bIsPlus,    // returns:  T=Is a plus
                                                &bIsMinus,   // returns:  T=Is a minus
                                                &bIsLastLeaf) )// returns:  T=Is Last Leaf
                    {
                        // returns:  T=cell has a plus or minus;  F=not
                        if( bIsPlus)
                            TreeImage = TREE_IMAGE_FOLDER_CLOSED;
                        else
                            TreeImage = TREE_IMAGE_FOLDER_OPEN;
                    }
                }
                SetImage( TreeImage);
            }
        }

        prect->left += GetTreeIndent();

    }
    pDC->RestoreDC(nSavedDC);
    return TRUE;
}
示例#20
0
// EFW - Various changes to make it draw cells better when using alternate
// color schemes.  Also removed printing references as that's now done
// by PrintCell() and fixed the sort marker so that it doesn't draw out
// of bounds.
BOOL CGridCellBase::Draw(CDC* pDC, int nRow, int nCol, CRect rect,  BOOL bEraseBkgnd /*=TRUE*/)
{
    // Note - all through this function we totally brutalise 'rect'. Do not
    // depend on it's value being that which was passed in.
//Used for merge cells
	//by Huang Wei
	if(	m_Hide && !IsMerged())
	{
		return TRUE;
	}

    CGridCtrl* pGrid = GetGrid();
    ASSERT(pGrid);

    if (!pGrid || !pDC)
        return FALSE;

    if( rect.Width() <= 0 || rect.Height() <= 0)  // prevents imagelist item from drawing even
        return FALSE;                             //  though cell is hidden

    //TRACE3("Drawing %scell %d, %d\n", IsFixed()? _T("Fixed ") : _T(""), nRow, nCol);

    int nSavedDC = pDC->SaveDC();
    pDC->SetBkMode(TRANSPARENT);

    // Get the default cell implementation for this kind of cell. We use it if this cell
    // has anything marked as "default"
    CGridDefaultCell *pDefaultCell = (CGridDefaultCell*) GetDefaultCell();
    if (!pDefaultCell)
        return FALSE;

    // Set up text and background colours
    COLORREF TextClr, TextBkClr;

    TextClr = (GetTextClr() == CLR_DEFAULT)? pDefaultCell->GetTextClr() : GetTextClr();
    if (GetBackClr() == CLR_DEFAULT)
        TextBkClr = pDefaultCell->GetBackClr();
    else
    {
        bEraseBkgnd = TRUE;
        TextBkClr = GetBackClr();
    }

    // Draw cell background and highlighting (if necessary)
    if ( IsFocused() || IsDropHighlighted() )
    {
        // Always draw even in list mode so that we can tell where the
        // cursor is at.  Use the highlight colors though.
        if(GetState() & GVIS_SELECTED)
        {
            TextBkClr = ::GetSysColor(COLOR_HIGHLIGHT);
            TextClr = ::GetSysColor(COLOR_HIGHLIGHTTEXT);
            bEraseBkgnd = TRUE;
        }

        rect.right++; rect.bottom++;    // FillRect doesn't draw RHS or bottom
        if (bEraseBkgnd)
        {
            TRY 
            {
                CBrush brush(TextBkClr);
                pDC->FillRect(rect, &brush);
            } 
            CATCH(CResourceException, e)
            {
                //e->ReportError();
            }
            END_CATCH
        }

        // Don't adjust frame rect if no grid lines so that the
        // whole cell is enclosed.
        if(pGrid->GetGridLines() != GVL_NONE)
        {
            rect.right--;
            rect.bottom--;
        }

        if (pGrid->GetFrameFocusCell())
        {
                // Use same color as text to outline the cell so that it shows
                // up if the background is black.
            TRY 
            {
                CBrush brush(TextClr);
                pDC->FrameRect(rect, &brush);
            }
            CATCH(CResourceException, e)
            {
                //e->ReportError();
            }
            END_CATCH
        }
        pDC->SetTextColor(TextClr);

        // Adjust rect after frame draw if no grid lines
        if(pGrid->GetGridLines() == GVL_NONE)
        {
            rect.right--;
            rect.bottom--;
        }

		//rect.DeflateRect(0,1,1,1);  - Removed by Yogurt
    }
示例#21
0
bool CMap::Init( GDE::CDataParser* pParser )
{
	if ( false == pParser->GetValue( m_uNumTiles, "Main", "TileCount" ) )
	{
		pParser->Release();
		assert_now( "Unable to find a Main:TileCount parameter" );
		return false;
	}

	if ( false == pParser->GetValue( m_uWidth, "Main", "Width" ) )
	{
		pParser->Release();
		assert_now( "Unable to find a Main:Width parameter" );
		return false;
	}

	if ( false == pParser->GetValue( m_uHeight, "Main", "Height" ) )
	{
		pParser->Release();
		assert_now( "Unable to find a Main:Height parameter" );
		return false;
	}

	m_pGrid = new CGrid[m_uHeight*m_uWidth];

	m_pTiles = new CTile[m_uNumTiles];
	for ( UINT32 i=0; i<m_uNumTiles; i++ )
	{
		m_pTiles[i].Clear();
	}

	CTile* pTileLookup[256];
	for ( UINT32 i=0; i<256; i++ )
	{
		pTileLookup[i] = NULL;
	}

	for ( UINT32 i=0; i<m_uNumTiles; i++ )
	{
		if ( false == m_pTiles[i].Init( i, pParser ) )
		{
			assert_now( "Error parsing tile %d", i );
			pParser->Release();
			return false;
		}
		pTileLookup[m_pTiles[i].GetAlias()] = m_pTiles + i;
	}

	// now all the tiles are created we can read in the map!
	char strRowName[16];
	UINT8* strRow = new UINT8[m_uWidth+1];
	for ( UINT32 y=0; y<m_uHeight; y++ )
	{
		for ( UINT32 x=0; x<m_uWidth; x++ )
		{
			strRow[x] = 0;
		}
		sprintf_s( strRowName, "Row%02d", y );
		if ( false == pParser->GetString( reinterpret_cast<char*>(strRow), m_uWidth+1, "Map", strRowName ) )
		{
			assert_now( "Unable to find %s", strRow );
			for ( UINT32 x=0; x<m_uWidth; x++ )
			{
				GetGrid( x, y )->Init( m_pTiles );
			}
		}
		for ( UINT32 x=0; x<m_uWidth; x++ )
		{
			CTile* pTile = pTileLookup[strRow[x]];
			if ( NULL == pTile )
			{
				assert_now( "Invalid tile at %d,%d:%c", x, y, strRow[x] );
				GetGrid( x, y )->Init( m_pTiles );				
			} else
			{
				GetGrid( x, y )->Init( pTile );				
			}
		}
	}

	delete[] strRow;

	// now do the second pass init:
	for ( UINT32 i=0; i<m_uHeight*m_uWidth; i++ )
	{
		m_pGrid[i].InitNeighbours();
	}
	return true;
}
示例#22
0
CGrid*	CMap::GetGridOnScreen( CFVec2Arg vPos )
{
	UINT32 uX = UINT32( vPos.X() )/uTILE_WIDTH;
	UINT32 uY = UINT32( vPos.Y() )/uTILE_HEIGHT;
	return GetGrid( uX, uY );
}
示例#23
0
static int Integrate(This *t, real *integral, real *error, real *prob)
{
  bin_t *bins;
  count dim, comp;
  int fail;
  struct {
    count niter;
    number nsamples, neval;
    Cumulants cumul[NCOMP];
    Grid grid[NDIM];
  } state;
  int statemsg = VERBOSE;
  struct stat st;

  if( VERBOSE > 1 ) {
    char s[512];
    sprintf(s, "Vegas input parameters:\n"
      "  ndim " COUNT "\n  ncomp " COUNT "\n"
      "  epsrel " REAL "\n  epsabs " REAL "\n"
      "  flags %d\n  seed %d\n"
      "  mineval " NUMBER "\n  maxeval " NUMBER "\n"
      "  nstart " NUMBER "\n  nincrease " NUMBER "\n"
      "  nbatch " NUMBER "\n  gridno %d\n"
      "  statefile \"%s\"",
      t->ndim, t->ncomp,
      t->epsrel, t->epsabs,
      t->flags, t->seed,
      t->mineval, t->maxeval,
      t->nstart, t->nincrease, t->nbatch,
      t->gridno, t->statefile);
    Print(s);
  }

  if( BadComponent(t) ) return -2;
  if( BadDimension(t) ) return -1;

  FrameAlloc(t, ShmRm(t));
  ForkCores(t);
  Alloc(bins, t->nbatch*t->ndim);

  if( (fail = setjmp(t->abort)) ) goto abort;

  IniRandom(t);

  if( t->statefile && *t->statefile == 0 ) t->statefile = NULL;

  if( t->statefile &&
      stat(t->statefile, &st) == 0 &&
      st.st_size == sizeof state && (st.st_mode & 0400) ) {
    cint h = open(t->statefile, O_RDONLY);
    read(h, &state, sizeof state);
    close(h);
    t->rng.skiprandom(t, t->neval = state.neval);

    if( VERBOSE ) {
      char s[256];
      sprintf(s, "\nRestoring state from %s.", t->statefile);
      Print(s);
    }
  }
  else {
    state.niter = 0;
    state.nsamples = t->nstart;
    Zap(state.cumul);
    GetGrid(t, state.grid);
  }

  /* main iteration loop */

  for( ; ; ) {
    number nsamples = state.nsamples;
    creal jacobian = 1./nsamples;
    Grid margsum[NCOMP][NDIM];

    Zap(margsum);

    for( ; nsamples > 0; nsamples -= t->nbatch ) {
      cnumber n = IMin(t->nbatch, nsamples);
      real *w = t->frame;
      real *x = w + n;
      real *f = x + n*t->ndim;
      real *lastf = f + n*t->ncomp;
      bin_t *bin = bins;

      while( x < f ) {
        real weight = jacobian;

        t->rng.getrandom(t, x);

        for( dim = 0; dim < t->ndim; ++dim ) {
          creal pos = *x*NBINS;
          ccount ipos = (count)pos;
          creal prev = (ipos == 0) ? 0 : state.grid[dim][ipos - 1];
          creal diff = state.grid[dim][ipos] - prev; 
          *x++ = prev + (pos - ipos)*diff;
          *bin++ = ipos;
          weight *= diff*NBINS;
        }

        *w++ = weight;
      }

      DoSample(t, n, w, f, t->frame, state.niter + 1);

      bin = bins;
      w = t->frame;

      while( f < lastf ) {
        creal weight = *w++;

        for( comp = 0; comp < t->ncomp; ++comp ) {
          real wfun = weight*(*f++);
          if( wfun ) {
            Cumulants *c = &state.cumul[comp];
            Grid *m = margsum[comp];

            c->sum += wfun;
            c->sqsum += wfun *= wfun;
            for( dim = 0; dim < t->ndim; ++dim )
              m[dim][bin[dim]] += wfun;
          }
        }

        bin += t->ndim;
      }
    }

    fail = 0;

    /* compute the integral and error values */

    for( comp = 0; comp < t->ncomp; ++comp ) {
      Cumulants *c = &state.cumul[comp];
      real avg, sigsq;
      real w = Weight(c->sum, c->sqsum, state.nsamples);

      sigsq = 1/(c->weightsum += w);
      avg = sigsq*(c->avgsum += w*c->sum);

      c->avg = LAST ? (sigsq = 1/w, c->sum) : avg;
      c->err = sqrt(sigsq);
      fail |= (c->err > MaxErr(c->avg));

      if( state.niter == 0 ) c->guess = c->sum;
      else {
        c->chisum += w *= c->sum - c->guess;
        c->chisqsum += w*c->sum;
      }
      c->chisq = c->chisqsum - avg*c->chisum;

      c->sum = c->sqsum = 0;
    }

    if( VERBOSE ) {
      char s[128 + 128*NCOMP], *p = s;

      p += sprintf(p, "\n"
        "Iteration " COUNT ":  " NUMBER " integrand evaluations so far",
        state.niter + 1, t->neval);

      for( comp = 0; comp < t->ncomp; ++comp ) {
        cCumulants *c = &state.cumul[comp];
        p += sprintf(p, "\n[" COUNT "] "
          REAL " +- " REAL "  \tchisq " REAL " (" COUNT " df)",
          comp + 1, c->avg, c->err, c->chisq, state.niter);
      }

      Print(s);
    }

    if( fail == 0 && t->neval >= t->mineval ) {
      if( t->statefile && KEEPFILE == 0 ) unlink(t->statefile);
      break;
    }

    if( t->neval >= t->maxeval && t->statefile == NULL ) break;

    if( t->ncomp == 1 )
      for( dim = 0; dim < t->ndim; ++dim )
        RefineGrid(t, state.grid[dim], margsum[0][dim]);
    else {
      for( dim = 0; dim < t->ndim; ++dim ) {
        Grid wmargsum;
        Zap(wmargsum);
        for( comp = 0; comp < t->ncomp; ++comp ) {
          real w = state.cumul[comp].avg;
          if( w != 0 ) {
            creal *m = margsum[comp][dim];
            count bin;
            w = 1/Sq(w);
            for( bin = 0; bin < NBINS; ++bin )
              wmargsum[bin] += w*m[bin];
          }
        }
        RefineGrid(t, state.grid[dim], wmargsum);
      }
    }

    ++state.niter;
    state.nsamples += t->nincrease;

    if( t->statefile ) {
      cint h = creat(t->statefile, 0666);
      if( h != -1 ) {
        state.neval = t->neval;
        write(h, &state, sizeof state);
        close(h);

        if( statemsg ) {
          char s[256];
          sprintf(s, "\nSaving state to %s.", t->statefile);
          Print(s);
          statemsg = false;
        }
      }
      if( t->neval >= t->maxeval ) break;
    }
  }

  for( comp = 0; comp < t->ncomp; ++comp ) {
    cCumulants *c = &state.cumul[comp];
    integral[comp] = c->avg;
    error[comp] = c->err;
    prob[comp] = ChiSquare(c->chisq, state.niter);
  }

abort:
  PutGrid(t, state.grid);
  free(bins);
  WaitCores(t);
  FrameFree(t);

  return fail;
}
示例#24
0
/*****************************************************************************
Called during all the mouse events associated with clicking a control
embedded within a cell.  Override to have more elaborate handling like
implementing radio button logic.

*****************************************************************************/
BOOL CGridBtnCellBase::ClickedCellCtl(  UINT uMsg,      // Command that invoked.  e.g. WM_LBUTTONDOWN
                                        int aiWhich)    // zero-based index of image to draw
// returns:  T=redraw occurred / F=no redraw
{
    if( aiWhich < 0
        || aiWhich >= GetDrawCtlNbrMax() )
    {
        ASSERT( FALSE);
        return FALSE;
    }

    UINT uiState = GetDrawCtlState( aiWhich);
    if( uiState & DFCS_INACTIVE)
        return FALSE;   // button is inactive -- don't do anything

    m_sLastCtlClicked = (short)aiWhich;
    UINT iType = GetDrawCtlType( aiWhich);

    switch( uMsg)
    {
        case WM_LBUTTONDOWN:
            // appears pushed in
            uiState |= DFCS_PUSHED;
            SetDrawCtlState( aiWhich, uiState);
            break;

        case WM_LBUTTONUP:
        case WM_LBUTTONDBLCLK:
            // appears pushed out
            uiState &= (~DFCS_PUSHED);

            // auto check / uncheck controls, too
            if( iType == DFC_BUTTON )
            {
                BOOL bIsMbrRadioGrp = GetDrawCtlIsMbrRadioGrp( aiWhich);

                if( uiState & DFCS_BUTTONRADIO
                    || bIsMbrRadioGrp )
                {
                    // radio buttons or any button flagged as being part
                    //  of a radio group will be made to look pressed down
                    //  while pushing-up / unchecking all other members
                    //  of the radio group

                    const int iCtlNbr = GetDrawCtlNbr();
                    UINT uiStateRadio;

                    for( int i1=0; i1 < iCtlNbr; i1++)
                    {
                        if( i1 != aiWhich)
                        {
                            uiStateRadio = GetDrawCtlState( i1);
                            bIsMbrRadioGrp = GetDrawCtlIsMbrRadioGrp( i1);

                            if( uiStateRadio & DFCS_BUTTONRADIO
                                || bIsMbrRadioGrp )
                            {
                                uiStateRadio &= (~( DFCS_PUSHED | DFCS_CHECKED)  );
                                                    // push out and uncheck
                                SetDrawCtlState( i1, uiStateRadio);
                            }
                        }
                    }
                    uiState |= DFCS_CHECKED;  // check
                    if( !(uiState & DFCS_BUTTONRADIO) )
                        uiState |= DFCS_PUSHED;  // press in if not real radio button

                }
                else if(  !( uiState & ALL_BUT_BTN_CHK)  )
                {
                    // not a pushbutton -- it's a check box
                    //  (can't check for DFCS_BUTTONCHECK directly since it is bit 0)
                    if( uiState & DFCS_CHECKED)
                        uiState &= (~DFCS_CHECKED); // uncheck
                    else
                        uiState |= DFCS_CHECKED;    // check
                }
            }

            SetDrawCtlState( aiWhich, uiState);
            break;

        default:
            ASSERT( FALSE); // gotta handle new message
            return FALSE;
    }

    CGridCtrl* pGrid = GetGrid();
    ASSERT( pGrid);

    pGrid->RedrawCell( m_iRow, m_iCol);

    return TRUE;
}
示例#25
0
文件: main.cpp 项目: DaveAckley/MFM
    void ReinitEden()
    {
      OurGrid & mainGrid = GetGrid();
      OurStatsRenderer & srend = GetStatsRenderer();

      OurAtom atom(Element_Dreg<OurCoreConfig>::THE_INSTANCE.GetDefaultAtom());
      OurAtom sorter(Element_Sorter<OurCoreConfig>::THE_INSTANCE.GetDefaultAtom());
      OurAtom emtr(Element_Emitter<OurCoreConfig>::THE_INSTANCE.GetDefaultAtom());
      OurAtom cnsr(Element_Consumer<OurCoreConfig>::THE_INSTANCE.GetDefaultAtom());

      m_sortingSlots[0].Set(mainGrid, "Data in",
                            Element_Emitter<OurCoreConfig>::THE_INSTANCE.GetType(),
                            Element_Emitter<OurCoreConfig>::DATUMS_EMITTED_SLOT,
                            Element_Emitter<OurCoreConfig>::DATA_SLOT_COUNT,
                            true);
      m_sortingSlots[1].Set(mainGrid, "Overflow",
                            Element_Emitter<OurCoreConfig>::THE_INSTANCE.GetType(),
                            Element_Emitter<OurCoreConfig>::DATUMS_REJECTED_SLOT,
                            Element_Emitter<OurCoreConfig>::DATA_SLOT_COUNT,
                            true);

      m_sortingSlots[2].Set(mainGrid, "Data out",
                            Element_Consumer<OurCoreConfig>::THE_INSTANCE.GetType(),
                            Element_Consumer<OurCoreConfig>::DATUMS_CONSUMED_SLOT,
                            Element_Consumer<OurCoreConfig>::DATA_SLOT_COUNT,
                            true);
      m_sortingSlots[3].Set(mainGrid, "Sort error",
                            Element_Consumer<OurCoreConfig>::THE_INSTANCE.GetType(),
                            Element_Consumer<OurCoreConfig>::TOTAL_BUCKET_ERROR_SLOT,
                            Element_Consumer<OurCoreConfig>::DATA_SLOT_COUNT,
                            true);

      for (u32 i = 0; i < 4; ++i)
        srend.DisplayDataReporter(&m_sortingSlots[i]);

      //      sorter.SetStateField(0,32,DATA_MINVAL + ((DATA_MAXVAL - DATA_MINVAL) / 2));  // Default threshold
      sorter.SetStateField(0,32, DATA_MINVAL);  // Default threshold

      u32 realWidth = P::TILE_WIDTH - P::EVENT_WINDOW_RADIUS * 2;

      SPoint aloc(20, 30);
      SPoint sloc(20, 10);
      SPoint eloc(GRID_WIDTH*realWidth-2, GRID_HEIGHT*realWidth/2);
      SPoint cloc(0, GRID_HEIGHT*realWidth/2);

      for(u32 x = 0; x < mainGrid.GetWidth(); x++)
        {
          for(u32 y = 0; y < mainGrid.GetHeight(); y++)
            {
              for(u32 z = 0; z < 4; z++)
                {
                  aloc.Set(10 + x * realWidth + z, 14 + y * realWidth);
                  sloc.Set(11 + x * realWidth + z, 15 + y * realWidth);
                  mainGrid.PlaceAtom(sorter, sloc);
                  mainGrid.PlaceAtom(atom, aloc);
                }
            }
        }
      mainGrid.PlaceAtom(emtr, eloc);
      mainGrid.PlaceAtom(cnsr, cloc);

    }
/*****************************************************************************
Draws "+", "-" and lines that show a tree graphic

*****************************************************************************/
void CGridTreeCellBase::TreeDrawGraphic(CDC* apDC,      // current CDC
                                    CRect aRect)    // coordinates of bounding cell rectangle
{
    ASSERT( apDC != NULL);
    ASSERT( m_pTreeColumn != NULL);
    ASSERT( m_pTreeColumn->GetAllowDraw());

    int iNbrTreeElements = m_pTreeColumn->GetRowCount() - m_pTreeColumn->GetFixedRowCount();

    // get current level
    unsigned char ucLevelCurrent = GetLevel();
    ASSERT( IsViewable() ); // can't deal with hidden rows!
    if( ucLevelCurrent <= 0)
    {
        if( m_pTreeColumn->GetTreeUsesImages())
            SetImage( TREE_IMAGE_DOCUMENT);
        return;     // no + / - box if level 0
    }

    BOOL bIsNextShowing;
    unsigned char ucLevelNext;
    int iLineStop;


    if( m_pTreeColumn->GetDefTreeIndent() < TREE_BOX_MARGIN * 3)
        return; // too small to draw the graphic

    CRect RectRel;
    TreeGetBoxRelCoords( &RectRel);      // returns: relative coordinates
    CRect RectBox( RectRel);
    RectBox.OffsetRect( aRect.left, aRect.top);

    int iXCenter = RectBox.left + ( (RectBox.right - RectBox.left) / 2);
    int iYCenter = RectBox.top + ( (RectBox.bottom - RectBox.top) / 2);

    CPen psPen(PS_SOLID, 1, m_pTreeColumn->GetTreeLineColor() );
    CPen* pOldPen = apDC->SelectObject(&psPen);

    TREE_IMAGE TreeImage = TREE_IMAGE_DOCUMENT;

    // is it the very last row?
    if( !GetForcePlus()  &&  m_iRow >= m_pTreeColumn->GetRowCount() - 1)
    {
        iXCenter -= m_pTreeColumn->GetDefTreeIndent();

        // draw |__ (with long horizontal)
        if( TryMoveTo( aRect, apDC, iXCenter, aRect.top) )
            if( TryLineTo( aRect, apDC, iXCenter, iYCenter) )
                TryLineTo( aRect, apDC, RectBox.right, iYCenter);

        apDC->SelectObject(pOldPen);
        if( m_pTreeColumn->GetTreeUsesImages())
            SetImage( TreeImage);
        return;
    }

    // is it a plus or minus?  Check up to all remaining entries for an answer
    BOOL bIsPlus;
    BOOL bIsMinus;
    BOOL bIsLastLeaf;
    CGridCtrl* pGrid = GetGrid();
    ASSERT( pGrid != NULL);

    int iVertLineBottom = aRect.bottom + 1; // if drawing a horizontal line,
                                            //  overwrite the grid line in case it is
                                            //  not displayed

    BOOL bIsBranch = m_pTreeColumn->TreeCellHasPlusMinus(
                                m_iRow,          // row of Cell to check
                                &bIsPlus,    // returns:  T=Is a plus
                                &bIsMinus,   // returns:  T=Is a minus
                                &bIsLastLeaf);// returns:  T=Is Last Leaf

    if( bIsBranch )
    {
        // returns:  T=cell has a plus or minus;  F=not

        if( bIsPlus)
            TreeImage = TREE_IMAGE_FOLDER_CLOSED;
        else
            TreeImage = TREE_IMAGE_FOLDER_OPEN;

        // draw a square box
        BOOL bCanDrawRectangle =    aRect.PtInRect( CPoint( RectBox.left, RectBox.top ))
                                    && aRect.PtInRect( CPoint( RectBox.right, RectBox.bottom ));

        if( bCanDrawRectangle )
        {
            apDC->Rectangle(    RectBox.left,
                                RectBox.top,
                                RectBox.right,
                                RectBox.bottom);
        }

        // draw a minus sign
        if( TryMoveTo( aRect, apDC, RectBox.left + TREE_BOX_MARGIN, iYCenter) )
            TryLineTo( aRect, apDC, RectBox.right - TREE_BOX_MARGIN, iYCenter);

        // draw small horizontal tick just to the left of the box if not
        //  level 1
        if( ucLevelCurrent > 1)
        {
            // draw -
            if( TryMoveTo( aRect, apDC, iXCenter - m_pTreeColumn->GetDefTreeIndent(), iYCenter) )
                TryLineTo( aRect, apDC, RectBox.left, iYCenter);
        }

        if( bIsPlus)
        {
            // ... make it into a plus sign
            if( TryMoveTo( aRect, apDC, iXCenter, RectBox.top + TREE_BOX_MARGIN) )
                TryLineTo( aRect, apDC, iXCenter, RectBox.bottom - TREE_BOX_MARGIN);
        }
        else
        {
            // it's a minus sign, so draw vertical tick below box center

            // draw |
            if( TryMoveTo( aRect, apDC, iXCenter, RectBox.bottom) )
                TryLineTo( aRect, apDC, iXCenter, iVertLineBottom);
        }

    }
    else if( ucLevelCurrent > 1)
    {
        // it's not a box, it's a leaf of the tree.  Just draw a horizontal line

        CGridTreeCellBase* pGridTreeCellBase = (CGridTreeCellBase*)pGrid->GetCell( m_iRow + 1, m_pTreeColumn->GetColumnWithTree());
        if( pGridTreeCellBase == NULL)
            return;

        bIsNextShowing = pGridTreeCellBase->IsViewable();
        ucLevelNext = pGridTreeCellBase->GetLevel();


        if( ucLevelCurrent > ucLevelNext)
        {
            bIsLastLeaf = TRUE;
        }

        // draw -
        if( TryMoveTo( aRect, apDC, iXCenter - m_pTreeColumn->GetDefTreeIndent(), iYCenter) )
            TryLineTo( aRect, apDC, iXCenter, iYCenter);
    }

    // draw nearest to text vertical lines that appear to the left of the box for all
    //  levels except level 1
    if( ucLevelCurrent > 1)
    {
        iXCenter -= m_pTreeColumn->GetDefTreeIndent();
        if( bIsLastLeaf)
            iLineStop = iYCenter;
        else
            iLineStop = iVertLineBottom;

        // draw |
        if( TryMoveTo( aRect, apDC, iXCenter, aRect.top) )
            TryLineTo( aRect, apDC, iXCenter, iLineStop);
    }

    BOOL bFoundBranch;
    unsigned char ucLevelToCheck = ucLevelCurrent;

    // draw vertical lines that appear to the left of the box for all appropriate
    //  levels except level 1
    for( int i1=ucLevelCurrent - 1; i1 > 1; i1--)
    {
        bFoundBranch = FALSE;

        int iStartPt = m_iRow + 1;

        for( int i2=iStartPt; i2 <= iNbrTreeElements; i2++)
        {
            CGridTreeCellBase* pGridTreeCellBase = (CGridTreeCellBase*)pGrid->GetCell(
                                                i2,
                                                m_pTreeColumn->GetColumnWithTree());
            if( pGridTreeCellBase == NULL)
                return;

            ucLevelNext = pGridTreeCellBase->GetLevel();

            if( ucLevelNext + 1 < ucLevelToCheck)
                break;

            if( ucLevelNext + 1 == ucLevelToCheck)
            {
                bIsNextShowing = pGridTreeCellBase->IsViewable();
                if( bIsNextShowing)
                    bFoundBranch = TRUE;
                break;
            }

        }

        iXCenter -= m_pTreeColumn->GetDefTreeIndent();

        if( bFoundBranch)
        {
            // draw |
            if( TryMoveTo( aRect, apDC, iXCenter, aRect.top) )
                TryLineTo( aRect, apDC, iXCenter, iVertLineBottom);
        }
        ucLevelToCheck--;   // each loop heads to level 1
    }

    // cleanup
    apDC->SelectObject(pOldPen);

    if( m_pTreeColumn->GetTreeUsesImages())
        SetImage( TreeImage);

}
示例#27
0
// Returns a pointer to a cell that holds default values for this particular type of cell
CGridCellBase* CGridCellBase::GetDefaultCell() const
{
    if (GetGrid())
        return GetGrid()->GetDefaultCell(IsFixedRow(), IsFixedCol());
    return NULL;
}
示例#28
0
void wxExSampleFrame::OnCommand(wxCommandEvent& event)
{
  m_Statistics.Inc(wxString::Format("%d", event.GetId()));

  auto* editor = GetSTC();
  auto* grid = GetGrid();
  auto* listview = GetListView();

  if (
    (event.GetId() == wxID_UNDO ||
     event.GetId() == wxID_REDO ||
     event.GetId() == wxID_DELETE ||
     event.GetId() == wxID_SELECTALL ||
     event.GetId() == wxID_JUMP_TO) ||
    (event.GetId() >= wxID_CUT && event.GetId() <= wxID_CLEAR))
  {
    if (editor != NULL)
    {
      wxPostEvent(editor, event);
    }
    else if (grid != NULL)
    {
      wxPostEvent(grid, event);
    }
    else if (listview != NULL)
    {
      wxPostEvent(listview, event);
    }
  }
  else
  {
    switch (event.GetId())
    {
    case wxID_ABOUT:
      {
      wxAboutDialogInfo info;
      info.SetIcon(GetIcon());
      info.SetVersion(wxExGetVersionInfo().GetVersionOnlyString());
      info.SetCopyright(wxExGetVersionInfo().GetCopyright());
      wxAboutBox(info);
      }
      break;
    case wxID_EXIT: Close(true); break;
    case wxID_OPEN:
      {
      wxExFileDialog dlg(this, &m_STC->GetFile());
      if (dlg.ShowModalIfChanged(true) == wxID_CANCEL) return;
  
      wxStopWatch sw;
      
      m_STC->Open(dlg.GetPath(), 0, wxEmptyString, m_FlagsSTC);
  
      const auto stop = sw.Time();
      wxLogStatus(wxString::Format(
        "wxExSTC::Open:%ld milliseconds, %d bytes", stop, m_STC->GetTextLength()));
      }
      break;
  
    case wxID_PREVIEW: m_ListView->PrintPreview(); break;
    case wxID_PRINT: m_ListView->Print(); break;
    case wxID_PRINT_SETUP: wxExPrinting::Get()->GetHtmlPrinter()->PageSetup(); break;
  
    case wxID_SAVE:
      m_STC->GetFile().FileSave();
  
      if (m_STC->GetFileName().GetFullPath() == 
          wxExLexers::Get()->GetFileName().GetFullPath())
      {
        wxExLexers::Get()->Read();
        wxLogMessage("File contains: %d lexers", wxExLexers::Get()->GetCount());
          // As the lexer might have changed, update status bar field as well.
  #if wxUSE_STATUSBAR
        UpdateStatusBar(m_STC, "PaneLexer");
  #endif
      }
      break;
  
    case ID_CONFIG_DLG: ShowConfigItems(); break;
    case ID_CONFIG_DLG_READONLY:
      {
      std::vector<wxExConfigItem> v;
  
      v.push_back(wxExConfigItem("File Picker", CONFIG_FILEPICKERCTRL));
  
      for (size_t j = 1; j <= 10; j++)
      {
        v.push_back(wxExConfigItem(wxString::Format("Integer%d", j), CONFIG_INT));
      }
  
      wxExConfigDialog* dlg = new wxExConfigDialog(
        this,
        v,
        "Config Dialog Readonly",
        0,
        1,
        wxCANCEL);
  
        dlg->Show();
      }
      break;
      
    case ID_PROCESS_SELECT:
      wxExProcess::ConfigDialog(this);
      break;
  
    case ID_PROCESS_RUN:
      m_Process.Execute(wxEmptyString);
      break;
      
    case ID_SHELL_COMMAND:
        m_STCShell->Prompt("\nHello '" + event.GetString() + "' from the shell");
      break;
      
    case ID_SHOW_VCS:
      {
      wxFileDialog openFileDialog(this, _("Open File"), "", "",
        "All files (*.*)|*.*", wxFD_OPEN|wxFD_FILE_MUST_EXIST);
  
      if (openFileDialog.ShowModal() == wxID_CANCEL)
        return;     // the user changed idea...
          
      wxArrayString ar;
      ar.Add(openFileDialog.GetPath());
      wxExVCS vcs(ar);
      wxLogMessage(vcs.GetName());
      
      if (vcs.GetEntry().SupportKeywordExpansion())
      {
        wxLogMessage("supports keyword expansion");
      }
      }
      break;
  
    case ID_STATISTICS_SHOW:
      m_Notebook->AddPage(m_Statistics.Show(m_Notebook), "Statistics");
      break;
  
    case ID_STC_CONFIG_DLG:
      wxExSTC::ConfigDialog(
        this,
        "Editor Options",
        wxExSTC::STC_CONFIG_MODELESS | wxExSTC::STC_CONFIG_WITH_APPLY);
      break;
      
    case ID_STC_ENTRY_DLG:
      {
      wxString text;
      
      for (auto i = 0; i < 100; i++)
      {
        text += wxString::Format("Hello from line: %d\n", i);
      }
      
      wxExSTCEntryDialog dlg(
        this,
        "Hello world",
        text,      
        "Greetings from " + wxTheApp->GetAppDisplayName());
        
        dlg.ShowModal();
      }
      break;
      
    case ID_STC_FLAGS:
      {
      long value = wxGetNumberFromUser(
        "Input:",
        wxEmptyString,
        "STC Open Flag",
        m_FlagsSTC,
        0,
        0xFFFF);
  
      if (value != -1)
      {
        m_FlagsSTC = value;
      }
      }
      break;
      
    case ID_STC_SPLIT:
      {
      wxExSTC* stc = new wxExSTC(*m_STC);
      m_Notebook->AddPage(
        stc,
        wxString::Format("stc%d", stc->GetId()),
        m_STC->GetFileName().GetFullName());
      stc->SetDocPointer(m_STC->GetDocPointer());
      }
      break;
      
    default:
      wxFAIL;
      break;
    }
  }
}
void
nsGridRowLeafLayout::PopulateBoxSizes(nsIBox* aBox, nsBoxLayoutState& aState, nsBoxSize*& aBoxSizes, nscoord& aMinSize, nscoord& aMaxSize, PRInt32& aFlexes)
{
  PRInt32 index = 0;
  nsGrid* grid = GetGrid(aBox, &index);
  PRBool isHorizontal = IsHorizontal(aBox);

  // Our base class SprocketLayout is giving us a chance to change the box sizes before layout
  // If we are a row lets change the sizes to match our columns. If we are a column then do the opposite
  // and make them match or rows.
  if (grid) {
    nsGridRow* column;
    PRInt32 count = grid->GetColumnCount(isHorizontal); 
    nsBoxSize* start = nsnull;
    nsBoxSize* last = nsnull;
    nsBoxSize* current = nsnull;
    nsIBox* child = aBox->GetChildBox();
    for (int i=0; i < count; i++)
    {
      column = grid->GetColumnAt(i,isHorizontal); 

      // make sure the value was computed before we use it.
      // !isHorizontal is passed in to invert the behavior of these methods.
      nscoord pref =
        grid->GetPrefRowHeight(aState, i, !isHorizontal); // GetPrefColumnWidth
      nscoord min = 
        grid->GetMinRowHeight(aState, i, !isHorizontal);  // GetMinColumnWidth
      nscoord max = 
        grid->GetMaxRowHeight(aState, i, !isHorizontal);  // GetMaxColumnWidth
      nscoord flex =
        grid->GetRowFlex(aState, i, !isHorizontal);       // GetColumnFlex
      nscoord left  = 0;
      nscoord right  = 0;
      grid->GetRowOffsets(aState, i, left, right, !isHorizontal); // GetColumnOffsets
      nsIBox* box = column->GetBox();
      PRBool collapsed = PR_FALSE;
      nscoord topMargin = column->mTopMargin;
      nscoord bottomMargin = column->mBottomMargin;

      if (box) 
        collapsed = box->IsCollapsed(aState);

      pref = pref - (left + right);
      if (pref < 0)
        pref = 0;

      // if this is the first or last column. Take into account that
      // our row could have a border that could affect our left or right
      // padding from our columns. If the row has padding subtract it.
      // would should always be able to garentee that our margin is smaller
      // or equal to our left or right
      PRInt32 firstIndex = 0;
      PRInt32 lastIndex = 0;
      nsGridRow* firstRow = nsnull;
      nsGridRow* lastRow = nsnull;
      grid->GetFirstAndLastRow(aState, firstIndex, lastIndex, firstRow, lastRow, !isHorizontal);

      if (i == firstIndex || i == lastIndex) {
        nsMargin offset = GetTotalMargin(aBox, isHorizontal);

        nsMargin border(0,0,0,0);
        // can't call GetBorderPadding we will get into recursion
        aBox->GetBorder(border);
        offset += border;
        aBox->GetPadding(border);
        offset += border;

        // subtract from out left and right
        if (i == firstIndex) 
        {
          if (isHorizontal)
           left -= offset.left;
          else
           left -= offset.top;
        }

        if (i == lastIndex)
        {
          if (isHorizontal)
           right -= offset.right;
          else
           right -= offset.bottom;
        }
      }
    
      // initialize the box size here 
      max = NS_MAX(min, max);
      pref = nsBox::BoundsCheck(min, pref, max);
   
      current = new (aState) nsBoxSize();
      current->pref = pref;
      current->min = min;
      current->max = max;
      current->flex = flex;
      current->bogus = column->mIsBogus;
      current->left = left + topMargin;
      current->right = right + bottomMargin;
      current->collapsed = collapsed;

      if (!start) {
        start = current;
        last = start;
      } else {
        last->next = current;
        last = current;
      }

      if (child && !column->mIsBogus)
        child = child->GetNextBox();

    }
    aBoxSizes = start;
  }

  nsSprocketLayout::PopulateBoxSizes(aBox, aState, aBoxSizes, aMinSize, aMaxSize, aFlexes);
}
示例#30
0
main(int argc, char *argv[])
{
  int myproc, numprocs, j, i;
  MPI_Comm comm;
  gridT *grid;
  physT *phys;
  propT *prop;
  sediT *sedi;
  spropT *sprop;
  waveT *wave;
  wpropT *wprop;

  StartMpi(&argc,&argv,&comm,&myproc,&numprocs);

  ParseFlags(argc,argv,myproc);
  
  
  if(GRID)
    GetGrid(&grid,myproc,numprocs,comm);
  else
    ReadGrid(&grid,myproc,numprocs,comm);


  if(SOLVE) {
    ReadProperties(&prop,myproc);
    InitializeVerticalGrid(&grid);
    AllocatePhysicalVariables(grid,&phys,prop);

   // if(prop->wave){
      InitializeWaveProperties(&wprop, prop, myproc);
      AllocateWaveVariables(grid, &wave, prop, wprop);
      InitializeWaveVariables(grid, wave, prop, wprop, myproc, comm);
      
   // }
    
    if(prop->sedi){
      InitializeSediProperties(prop, &sprop, myproc);
      AllocateSediVariables(grid, &sedi, sprop, prop);
      InitializeSediVariables(grid, sedi, prop, sprop, myproc, comm);
    }
    
    AllocateTransferArrays(&grid,myproc,numprocs,comm);
    
    OpenFiles(prop,myproc);
    
    if(RESTART){
      ReadPhysicalVariables(grid,phys,prop,sedi,sprop,wave,wprop,myproc,comm);
     
    }
    else{
      InitializePhysicalVariables(grid,phys,sedi,prop,sprop);
      
    }

    InputTides(grid, phys, prop, myproc);
    
    SetDragCoefficients(grid,phys,prop);
    
    if (prop->wave)
      if (wprop->wind_forcing){
    	ObtainKrigingCoef(grid, wave, wprop, myproc, numprocs);    
    	for (i = 0; i< wprop->nstation; i++)      
    	  InputWind(i, prop, wave,wprop,myproc,numprocs);
      }

   
    Solve(grid,phys,prop,sprop,sedi,wave,wprop,myproc,numprocs,comm);
   
    //    FreePhysicalVariables(grid,phys,prop);
    //    FreeTransferArrays(grid,myproc,numprocs,comm);   
  }

  EndMpi(&comm);
}