Exemplo n.º 1
0
int
vtkCellIntersections::VoxelIntersectWithLine(vtkVoxel *cell, double p1[3], 
    double p2[3], double& t, double x[3])
{
  double minPt[3], maxPt[3], xTemp[3];;
  double bounds[6], p21[3];
  int i;
 
  t = VTK_DOUBLE_MAX;
 
  cell->Points->GetPoint(0, minPt);
  cell->Points->GetPoint(7, maxPt);
 
  for (i=0; i<3; i++)
    {
    p21[i] = p2[i] - p1[i];
    bounds[2*i] = minPt[i];
    bounds[2*i+1] = maxPt[i];
    }
 
  if (!IntersectBox(bounds, p1, p21, xTemp))
    {
    return 0;
    }

  for (i=0; i<3; i++)
    {
    x[i] = xTemp[i];
    }
  t = vtkMath::Distance2BetweenPoints(p1, x); 
  return 1;
}
Exemplo n.º 2
0
BOOL CWCalendarView::OnSetActive() 
{
	// Open the document
	if (!CWView::OnSetActive())
		return FALSE;

	// Show final text
	m_strTopText.LoadString(IDS_WH_CALENDAR_FINAL);
	UpdateData(FALSE);

	// Use calendar style to edit the document
	CCalendarDoc* pDoc = (CCalendarDoc*)m_pDoc;
	CAL_PICTURE_STYLE PicStyle = ((CWCalendarPageContainer*)m_pContainer)->GetPictureStyle();
	pDoc->GotoPage(1);

	// Retrieve the bound for the current picture page & whole calendar
	PBOX PicBound = pDoc->GetPicturePageBound(pDoc->CurrentPageIndex());

	if (PicStyle == CAL_PICTURE_NONE)
	{
		// Remove picture page, front & back cover pages
		// ASSUME there is only one picture page to begin with
		pDoc->DocumentRecord()->delete_page(m_pDoc->GetPage(0));
		pDoc->GotoPage(0);
		pDoc->DocumentRecord()->delete_page(m_pDoc->GetPage(1));
		pDoc->InvalidateLastKnownPage();
	}
	DWORD dwAtPage = pDoc->CurrentPageIndex(); // current working page

	// Change the picture style
	CalendarObject* pCalendarObject = pDoc->find_calendar_object(dwAtPage);
	pDoc->SetPictureStyle(PicStyle);
	pCalendarObject->SetPictureStyle(PicStyle);

	// Retrieve a list of objects in the current page
   ObjectList* pObjectList = pDoc->object_list();
	PMGPageObject* pObject = (PMGPageObject*)pObjectList->first_object();

	// If we're removing pictures, loop through objects and remove anything
	// that's in the picture bound
	PPNT bottom_dims, top_dims;
	pDoc->GetPageDims(bottom_dims, top_dims);
	if (PicStyle == CAL_PICTURE_NONE)
	{
		long nMove = (bottom_dims.y - top_dims.y);
		while (pObject != NULL)
		{
			PBOX bound = ((RectPageObject*)pObject)->get_unrotated_bound();
			PBOX intersect;
			
			// If the bounds intersect, remove the object
			// otherwise, shift it up for rescale
			if (IntersectBox(&intersect, &bound, &PicBound))
			{
				PMGPageObject* pNextObject = (PMGPageObject*)pObject->next_object();
				pObjectList->detach(pObject);
				pObject->destroy();
				delete pObject;

				pObject = pNextObject;
			}
			else
			{
				// Move the object up
				bound.y0 -= nMove;
				bound.y1 -= nMove;
				((RectPageObject*)pObject)->set_unrotated_bound(bound);
				pObject->calc();
				pObject = (PMGPageObject*)pObject->next_object();
			}
		}
	}
	pDoc->RecalcPageSize();

	// May need to shift pictures over
	if (PicStyle == CAL_PICTURE_LEFT)
	{
		PPNT new_bottom_dims, new_top_dims;
		pDoc->GetPageDims(new_bottom_dims, new_top_dims);
		PPNT Move;
		Move.x = (new_bottom_dims.x - bottom_dims.x);
		Move.y = (new_bottom_dims.y - bottom_dims.y);

		// Apply changes to front, calendar, and back pages
		for (int i = 0; i < (int)pDoc->NumberOfPages(); i++)
		{
			pDoc->GotoPage(i);

			// Retrieve a list of objects in the current page
			ObjectList* pObjectList = pDoc->object_list();
			PMGPageObject* pObject = (PMGPageObject*)pObjectList->first_object();
			while (pObject != NULL)
			{
				PBOX bound = ((RectPageObject*)pObject)->get_unrotated_bound();
				PBOX intersect;
				
				// If the bounds don't intersect, we need to move the object
				if (!IntersectBox(&intersect, &bound, &PicBound))
				{
					bound.x0 += Move.x;
					bound.x1 += Move.x;
					bound.y0 += Move.y;
					bound.y1 += Move.y;
					((RectPageObject*)pObject)->set_unrotated_bound(bound);
					pObject->calc();
				}
				pObject = (PMGPageObject*)pObject->next_object();
			}
		}
		pDoc->GotoPage(dwAtPage);
	}

	// Resize the preview
	m_preview.SizePreview();

	// Retrieve selected calendar attributes
	CALENDAR_INFO info;
	short numcals;
	((CWCalendarPageContainer*)m_pContainer)->GetCalendarInfo(info, numcals);

	// Merge in calendar style structure
	CALENDAR_INFO old_info = pCalendarObject->get_calendar().get_info();
	info.style = old_info.style;

	// Change the date
	pDoc->ChangeCalendarDate(info);

	// Create the remaining pages
	DWORD dwPages = numcals-1;  // number of new pages to add
	DWORD dwTotalPages = pDoc->NumberOfPages(); // total pages in project
	PMGDatabase* pDatabase = pDoc->get_database(); // current database
	PageRecord* pSourcePage = NULL;  // source page for info/possible template 
	PageRecord* pNewPage = NULL; // new page 
	BOOL bCopy = TRUE;
	BOOL bPictures = (PicStyle == CAL_PICTURE_TOP || PicStyle == CAL_PICTURE_LEFT);
	DB_RECORD_NUMBER dbPage;
		
	// decide where to insert new pages, and pull the proper page
	// get last page
	if (bPictures)  // use 2nd to last page
	{
		dwTotalPages--;
		dwAtPage  = pDoc->NumberOfPages() -1; // total pages in project;
	}
	else
		dwAtPage  = pDoc->NumberOfPages(); // total pages in project;
	dbPage = dwTotalPages - 1;

	// get calendar from template source page and get calendar info
	CALENDAR_INFO ciCalInfo;
	pObject = NULL;
	
	// get source page
	pSourcePage = (PageRecord*)pDatabase->get_record(pDoc->GetPage(dbPage), NULL, RECORD_TYPE_Page);

	if (pSourcePage != NULL) // get calendar object from page
	{
		int index = 0;
		pObject = (PMGPageObject*)pSourcePage->objects()->first_object();
		
		// loop thru and find a calendar to get properties from
		do 
		{
			if (pObject->type() == OBJECT_TYPE_Calendar)
			{
				// copy calendar info
				Calendar cal = ((CalendarObject*)pObject)->get_calendar();
				ciCalInfo = cal.get_info();
				
				// get start date from date source page
				CalendarObject* pSrc = pDoc->find_calendar_object(dbPage);
				if (pSrc != NULL)
				{
					Calendar t = pSrc->get_calendar();
					ciCalInfo.year = t.get_info().year;
					ciCalInfo.month = t.get_info().month;
					ciCalInfo.week = t.get_info().week;
				}
				break;
			}
			else 
				pObject = (PMGPageObject*)pObject->next_object();
		} 
		while (pObject != NULL);
	}
	
	DWORD dwStartPage = dwAtPage;
	int numsteps;
	
	if (ciCalInfo.style.type == YEARLY) 
		numsteps = ((int)dwPages * 12) + 1;
	else 
		numsteps = (int)dwPages +1;

	CString strDlgTitle = "Adding page(s)...";
	CCalendarProgressDlg dlg (numsteps, strDlgTitle);
	dlg.Create(IDD_CALENDAR_PROGRESS);
	dlg.ShowWindow(SW_SHOW);
	dlg.Step();
	BeginWaitCursor();
	
	// create new pages
	while (dwPages-- != 0)
	{

		// insert new page
		if (!pDoc->AddPage(dwAtPage))
		{
			break;
		}

		// Lock the new page.
		pNewPage = (PageRecord*)pDatabase->get_record(pDoc->GetPage(dwAtPage), NULL, RECORD_TYPE_Page);

		if (pNewPage != NULL)
		{
			// increment date
			if (ciCalInfo.style.type != YEARLY)
				IncrementCalendarDate(&ciCalInfo, TRUE);
			else 
			{
				ciCalInfo.year++;
			}

			if (pSourcePage != NULL) // creating a default calendar object for the page
			{
				// put a calendar on it
				CalendarObject * pNewCal = NULL;
				ObjectList ol (NULL);					
	
				if (!bCopy) // not copying, creating new calendars
				{					
					// build calendar create struct
					CALENDAR_CREATE_STRUCT ccs;
					ccs.info = &ciCalInfo;
					ccs.picture_style = pDoc->GetPictureStyle();
					//PPNT dim = pDoc->get_dimensions();
					pDoc->CalcCalendarSize(&ccs.bound);
					ccs.full_build = TRUE;
					
					if (ciCalInfo.style.type == YEARLY) 
					{
						// create and add yearly calendar to new page
						pDoc->CreateYearlyCalendar (&ccs, &ol, &dlg, ccs.picture_style == CAL_PICTURE_SAME);
						pDatabase->CopyObjectList(pNewPage->objects(), &ol, pNewPage->Id());	
					}
					else 
					{
						// create and add new weekly/monthly calendar
						pNewCal = pDatabase->create_calendar_object(&ccs);
						pNewPage->objects()->append(pNewCal);
						dlg.Step();
					}
				}
				else // copy from source page
				{
					// copy all objects from source page
					PMGPageObject* pObj = (PMGPageObject*)pSourcePage->objects()->first_object();
					do 
					{
						// copy object and append it to new list
						PMGPageObject * pDestObj = (PMGPageObject*)pObj->duplicate();
						ol.append(pDestObj);
						pObj = (PMGPageObject*)pObj->next_object();
					} 
					while (pObj != NULL);

					// and add them to the new page
					pDatabase->CopyObjectList(pNewPage->objects(), &ol, pNewPage->Id());	

					// replace calendar info and rebuild calendars
					// update calendar information to reflect new date
					pObj = (PMGPageObject*)pNewPage->objects()->first_object();
					
					// find calendar
					do 
					{
						if(pObj->type() == OBJECT_TYPE_Calendar)
						{
							if (ciCalInfo.style.type == YEARLY)
							{
								// save old calendar's month info, but update year info
								Calendar c = ((CalendarObject*)pObj)->get_calendar();
								CALENDAR_INFO ci = c.get_info();
								ciCalInfo.month = ci.month;
								ciCalInfo.week = ci.week;
							}

							pDoc->ReplaceCalendarInfo(ciCalInfo, (CalendarObject*)pObj);
							dlg.Step();								
							if (ciCalInfo.style.type != YEARLY)
								break; // should only be 1 calendar here.
						}

						pObj = (PMGPageObject*)pObj->next_object();
					} 
					while (pObj != NULL);	
				}
			}	
		}
		pNewPage->release();
		
		// increment current page, only if adding at end
		dwAtPage++;

 	} // while

	dlg.DestroyWindow();
	EndWaitCursor();
	
	// If we had a source page, release it now.
	if (pSourcePage != NULL)
	{
		pSourcePage->release();
	}
	
	return TRUE;
}