Beispiel #1
0
void LDLQuadLine::reportQuadSplit(bool flat, const int q1, const int q2,
								  const int q3, const int q4,
								  const int t1, const int t2, const int t3,
								  const int t4, const int t5, const int t6)
{
	UCSTRING q1Str, q2Str, q3Str, q4Str;
	UCSTRING t1Str, t2Str, t3Str, t4Str, t5Str, t6Str;
	CUCSTR errorTypeString =
		TCLocalStrings::get(_UC("LDLQuadLineConcave"));
	LDLErrorType errorType = LDLEConcaveQuad;

	if (!flat)
	{
		errorTypeString = TCLocalStrings::get(_UC("LDLQuadLineNonFlat"));
		errorType = LDLENonFlatQuad;
	}
	q1Str = printPoint(q1);
	q2Str = printPoint(q2);
	q3Str = printPoint(q3);
	q4Str = printPoint(q4);
	t1Str = printPoint(t1);
	t2Str = printPoint(t2);
	t3Str = printPoint(t3);
	t4Str = printPoint(t4);
	t5Str = printPoint(t5);
	t6Str = printPoint(t6);
	setWarning(errorType, TCLocalStrings::get(_UC("LDLQuadLineSpit")),
		errorTypeString, q1Str.c_str(), q2Str.c_str(), q3Str.c_str(),
		q4Str.c_str(), t1Str.c_str(), t2Str.c_str(), t3Str.c_str(),
		t4Str.c_str(), t5Str.c_str(), t6Str.c_str());
}
Beispiel #2
0
void LDLQuadLine::reportBadVertexOrder(int index1, int index2, int index3,
									   int index4)
{
	UCCHAR oldBuf[4][64];
	UCCHAR newBuf[4][64];
	int indices[4];
	int i;

	indices[0] = index1;
	indices[1] = index2;
	indices[2] = index3;
	indices[3] = index4;
	for (i = 0; i < 4; i++)
	{
		printPoint(i, oldBuf[i]);
		printPoint(indices[i], newBuf[i]);
	}
	if (m_actionFlags.bfcClip)
	{
		setError(LDLEVertexOrder,
			TCLocalStrings::get(_UC("LDLQuadLineBfcBadVertSeq")), oldBuf[0],
			oldBuf[1], oldBuf[2], oldBuf[3], newBuf[0], newBuf[1], newBuf[2],
			newBuf[3]);
	}
	else
	{
		setWarning(LDLEVertexOrder,
			TCLocalStrings::get(_UC("LDLQuadLineBadVertSeq")), oldBuf[0],
			oldBuf[1], oldBuf[2], oldBuf[3], newBuf[0], newBuf[1], newBuf[2],
			newBuf[3]);
	}
}
Beispiel #3
0
void LDLQuadLine::reportBadVertexOrder(int index1, int index2, int index3,
									   int index4)
{
	UCSTRING oldStr[4];
	UCSTRING newStr[4];
	int indices[4];
	int i;

	indices[0] = index1;
	indices[1] = index2;
	indices[2] = index3;
	indices[3] = index4;
	for (i = 0; i < 4; i++)
	{
		oldStr[i] = printPoint(i);
		newStr[i] = printPoint(indices[i]);
	}
	if (m_actionFlags.bfcClip)
	{
		setError(LDLEVertexOrder,
			TCLocalStrings::get(_UC("LDLQuadLineBfcBadVertSeq")),
			oldStr[0].c_str(), oldStr[1].c_str(), oldStr[2].c_str(),
			oldStr[3].c_str(), newStr[0].c_str(), newStr[1].c_str(),
			newStr[2].c_str(), newStr[3].c_str());
	}
	else
	{
		setWarning(LDLEVertexOrder,
			TCLocalStrings::get(_UC("LDLQuadLineBadVertSeq")),
			oldStr[0].c_str(), oldStr[1].c_str(), oldStr[2].c_str(),
			oldStr[3].c_str(), newStr[0].c_str(), newStr[1].c_str(),
			newStr[2].c_str(), newStr[3].c_str());
	}
}
Beispiel #4
0
void LDLQuadLine::reportQuadSplit(bool flat, const int q1, const int q2,
								  const int q3, const int q4,
								  const int t1, const int t2, const int t3,
								  const int t4, const int t5, const int t6)
{
	UCCHAR q1Buf[64], q2Buf[64], q3Buf[64], q4Buf[64];
	UCCHAR t1Buf[64], t2Buf[64], t3Buf[64], t4Buf[64], t5Buf[64], t6Buf[64];
	CUCSTR errorTypeString =
		TCLocalStrings::get(_UC("LDLQuadLineConcave"));
	LDLErrorType errorType = LDLEConcaveQuad;

	if (!flat)
	{
		errorTypeString = TCLocalStrings::get(_UC("LDLQuadLineNonFlat"));
		errorType = LDLENonFlatQuad;
	}
	printPoint(q1, q1Buf);
	printPoint(q2, q2Buf);
	printPoint(q3, q3Buf);
	printPoint(q4, q4Buf);
	printPoint(t1, t1Buf);
	printPoint(t2, t2Buf);
	printPoint(t3, t3Buf);
	printPoint(t4, t4Buf);
	printPoint(t5, t5Buf);
	printPoint(t6, t6Buf);
	setWarning(errorType, TCLocalStrings::get(_UC("LDLQuadLineSpit")),
		errorTypeString, q1Buf, q2Buf, q3Buf, q4Buf, t1Buf, t2Buf, t3Buf, t4Buf,
		t5Buf, t6Buf);
}
Beispiel #5
0
void LD3dsExporter::initSettings(void) const
{
	addSetting(LDExporterSetting(ls(_UC("3dsSeams")), m_seams,
		udKey("Seams").c_str()));
	LDExporterSetting *pGroup = &m_settings.back();
	addSetting(pGroup, LDExporterSetting(ls(_UC("3dsSeamWidth")), m_seamWidth,
		udKey("SeamWidth").c_str()));
}
Beispiel #6
0
bool OptionsCanvas::commitSettings(void)
{
	ucstring error;
	OptionUIList::iterator it;

	// First, walk through all settings and validate them.  If any of the
	// validations fails, stop and return false.  That means that if there are
	// any validation failures, the settings before the failure won't have their
	// values updated.
	for (it = m_optionUIs.begin();
		it != m_optionUIs.end(); it++)
	{
		OptionUI *optionUI = *it;

		if (!optionUI->validate(error))
		{
			if (error.size() > 0)
			{
				messageBoxUC(hWindow, error.c_str(), ls(_UC("Error")), MB_OK);
			}
			return false;
		}
	}
	// If we get here, validation succeeded, so save all the option values.
	for (it = m_optionUIs.begin();
		it != m_optionUIs.end(); it++)
	{
		OptionUI *optionUI = *it;

		optionUI->commit();
	}
	return true;
}
Beispiel #7
0
LDLFileLineArray *LDLQuadLine::splitConcaveQuad(void)
{
	LDLFileLineArray *fileLineArray = splitConcaveQuad(0, 1, 2, 3);

	if (!fileLineArray)
	{
		fileLineArray = splitConcaveQuad(0, 1, 3, 2);
	}
	if (!fileLineArray)
	{
		fileLineArray = splitConcaveQuad(0, 2, 1, 3);
	}
	if (!fileLineArray)
	{
		fileLineArray = splitConcaveQuad(0, 2, 3, 1);
	}
	if (!fileLineArray)
	{
		fileLineArray = splitConcaveQuad(0, 3, 1, 2);
	}
	if (!fileLineArray)
	{
		fileLineArray = splitConcaveQuad(0, 3, 2, 1);
	}
	if (!fileLineArray)
	{
		// All split attempts failed, the quad must not be flat.
		setError(LDLEConcaveQuad,
			TCLocalStrings::get(_UC("LDLQuadLineConcaveError")));
	}
	return fileLineArray;
}
Beispiel #8
0
bool LDLLineLine::parse(void)
{
	float x1, y1, z1;
	float x2, y2, z2;
	int lineType;

	if (sscanf(m_line, "%d %i %f %f %f %f %f %f", &lineType, &m_colorNumber,
		&x1, &y1, &z1, &x2, &y2, &z2) == 8)
	{
		m_points = new TCVector[2];
		m_points[0] = TCVector(x1, y1, z1);
		m_points[1] = TCVector(x2, y2, z2);
		if (!getMainModel()->getSkipValidation())
		{
			getMatchingPoints();
		}
		return true;
	}
	else
	{
		m_valid = false;
		setError(LDLEParse, TCLocalStrings::get(_UC("LDLLineParse")));
		return false;
	}
}
Beispiel #9
0
void BoundingBoxDialog::modelAlertCallback(TCAlert *alert)
{
	if (alert->getSender() == m_modelWindow)
	{
		if (ucstrcmp(alert->getMessageUC(), _UC("ModelLoaded")) == 0)
		{
			setModel(getModelViewer()->getMainModel());
			updateData();
		}
		else if (ucstrcmp(alert->getMessageUC(), _UC("ModelLoadCanceled")) == 0)
		{
			setModel(NULL);
			updateData();
		}
	}
}
Beispiel #10
0
void ModelTreeDialog::modelAlertCallback(TCAlert *alert)
{
	if (alert->getSender() == m_modelWindow)
	{
		if (ucstrcmp(alert->getMessageUC(), _UC("ModelLoaded")) == 0)
		{
			setModel(m_modelWindow->getModelViewer()->getMainModel());
			fillTreeView();
		}
		else if (ucstrcmp(alert->getMessageUC(), _UC("ModelLoadCanceled")) == 0)
		{
			setModel(NULL);
			fillTreeView();
		}
	}
}
Beispiel #11
0
void ModelTreeDialog::updateStatusText(void)
{
	HTREEITEM hItem = TreeView_GetSelection(m_hTreeView);

	if (hItem)
	{
		TVITEMEX item;

		memset(&item, 0, sizeof(item));
		item.mask = TVIF_PARAM;
		item.hItem = hItem;
		if (TreeView_GetItem(m_hTreeView, &item))
		{
			LDModelTree *tree = (LDModelTree *)item.lParam;

			if (tree)
			{
				sendMessageUC(m_hStatus, SB_SETTEXT, 0,
					(LPARAM)tree->getStatusText().c_str());
				return;
			}
		}
	}
	sendMessageUC(m_hStatus, SB_SETTEXT, 0, (LPARAM)ls(_UC("NoSelection")));
}
Beispiel #12
0
LDLFileLineArray *LDLQuadLine::removeColinearPoint(void)
{
	LDLFileLineArray *fileLineArray = NULL;
	LDLTriangleLine *triangleLine1 = NULL;
	LDLTriangleLine *triangleLine2 = NULL;

	switch (m_colinearIndex)
	{
	case 0:
		triangleLine1 = newTriangleLine(0, 1, 2);
		triangleLine2 = newTriangleLine(2, 3, 0);
		break;
	case 1:
		triangleLine1 = newTriangleLine(1, 2, 3);
		triangleLine2 = newTriangleLine(3, 0, 1);
		break;
	case 2:
		triangleLine1 = newTriangleLine(2, 3, 0);
		triangleLine2 = newTriangleLine(0, 1, 2);
		break;
	case 3:
		triangleLine1 = newTriangleLine(3, 0, 1);
		triangleLine2 = newTriangleLine(1, 2, 3);
		break;
	default:
		break;
	}
	if (triangleLine1 != NULL && triangleLine2 != NULL)
	{
		fileLineArray = new LDLFileLineArray(2);
		fileLineArray->addObject(triangleLine1);
		fileLineArray->addObject(triangleLine2);
		triangleLine1->release();
		triangleLine2->release();
	}
	if (fileLineArray != NULL)
	{
		setWarning(LDLEColinear, ls(_UC("LDLQuadLineCoLinear")),
			m_colinearIndex + 1);
	}
	else
	{
		setError(LDLEGeneral, ls(_UC("LDLQuadLineCoLinearError")));
	}
	return fileLineArray;
}
Beispiel #13
0
bool LDLQuadLine::parse(void)
{
	float x1, y1, z1;
	float x2, y2, z2;
	float x3, y3, z3;
	float x4, y4, z4;
	int lineType;

	if (sscanf(m_line, "%d %i %f %f %f %f %f %f %f %f %f %f %f %f", &lineType,
		&m_colorNumber, &x1, &y1, &z1, &x2, &y2, &z2, &x3, &y3, &z3,
		&x4, &y4, &z4) == 14)
	{
		std::string prefix = getTypeAndColorPrefix();
		std::stringstream ss;
		if (!prefix.empty())
		{
			ss << prefix << "  ";
		}
		else
		{
			ss << "4 " << m_colorNumber << "  ";
		}
		ss << x1 << " " << y1 << " " << z1 << "  ";
		ss << x2 << " " << y2 << " " << z2 << "  ";
		ss << x3 << " " << y3 << " " << z3 << "  ";
		ss << x4 << " " << y4 << " " << z4 << "  ";
		m_formattedLine = copyString(ss.str().c_str());
		m_points = new TCVector[4];
		m_points[0] = TCVector(x1, y1, z1);
		m_points[1] = TCVector(x2, y2, z2);
		m_points[2] = TCVector(x3, y3, z3);
		m_points[3] = TCVector(x4, y4, z4);
		if (!getMainModel()->getSkipValidation())
		{
			// Note that we don't care what the second matching index is,
			// because we only need to throw out one of the two points, so don't
			// bother to even read it.
			if (getMatchingPoints(&m_matchingIndex))
			{
				m_valid = false;
			}
			else
			{
				swapPointsIfNeeded();
				checkForColinearPoints();
			}
		}
		return true;
	}
	else
	{
		m_valid = false;
		setError(LDLEParse, TCLocalStrings::get(_UC("LDLQuadLineParse")));
		return false;
	}
}
Beispiel #14
0
LDLTriangleLine *LDLQuadLine::newTriangleLine(int p1, int p2, int p3)
{
	UCCHAR pointBuf1[64] = _UC("");
	UCCHAR pointBuf2[64] = _UC("");
	UCCHAR pointBuf3[64] = _UC("");
	UCCHAR ucNewLine[1024];
	char *newLine;
	LDLTriangleLine *retValue;

	printPoint(p1, pointBuf1);
	printPoint(p2, pointBuf2);
	printPoint(p3, pointBuf3);
	sucprintf(ucNewLine, COUNT_OF(ucNewLine), _UC("3 %ld %s %s %s"),
		m_colorNumber, pointBuf1, pointBuf2, pointBuf3);
	newLine = ucstringtombs(ucNewLine);
	retValue = new LDLTriangleLine(m_parentModel, newLine, m_lineNumber, m_line);
	delete newLine;
	return retValue;
}
Beispiel #15
0
LDLFileLineArray *LDLQuadLine::removeMatchingPoint(void)
{
	LDLFileLineArray *fileLineArray = removePoint(m_matchingIndex);

	if (fileLineArray)
	{
		UCSTRING pointStr;

		pointStr = printPoint(m_matchingIndex);
		setWarning(LDLEMatchingPoints,
			TCLocalStrings::get(_UC("LDLQuadLineIdentical")),
			m_matchingIndex + 1, pointStr.c_str());
	}
	else
	{
		setError(LDLEGeneral,
			TCLocalStrings::get(_UC("LDLQuadLineIdenticalError")));
	}
	return fileLineArray;
}
Beispiel #16
0
LDLFileLineArray *LDLQuadLine::removeMatchingPoint(void)
{
	LDLFileLineArray *fileLineArray = removePoint(m_matchingIndex);

	if (fileLineArray)
	{
		UCCHAR pointBuf[64] = _UC("");

		printPoint(m_matchingIndex, pointBuf);
		setWarning(LDLEMatchingPoints,
			TCLocalStrings::get(_UC("LDLQuadLineIdentical")),
			m_matchingIndex + 1, pointBuf);
	}
	else
	{
		setError(LDLEGeneral,
			TCLocalStrings::get(_UC("LDLQuadLineIdenticalError")));
	}
	return fileLineArray;
}
Beispiel #17
0
void BoundingBoxDialog::updateData(void)
{
	LDrawModelViewer *modelViewer = getModelViewer();
	if (m_model != NULL && modelViewer != NULL)
	{
		UCCHAR buf1[1024];
		UCCHAR buf2[1024];

		modelViewer->getBoundingMin().print(buf1, COUNT_OF(buf1));
		sucprintf(buf2, COUNT_OF(buf2), _UC("<%s>"), buf1);
		windowSetText(IDC_MIN_POINT, buf2);
		modelViewer->getBoundingMax().print(buf1, COUNT_OF(buf1));
		sucprintf(buf2, COUNT_OF(buf2), _UC("<%s>"), buf1);
		windowSetText(IDC_MAX_POINT, buf2);
	}
	else
	{
		windowSetText(IDC_MIN_POINT, _UC(""));
		windowSetText(IDC_MAX_POINT, _UC(""));
	}
}
Beispiel #18
0
LDExporterSetting *LDExporter::addEdgesSetting(LDExporterSetting *pGroup) const
{
	if (addSetting(pGroup, LDExporterSetting(ls(_UC("LDXEdges")), m_edges,
		udKey("Edges").c_str())))
	{
		return &m_settings.back();
	}
	else
	{
		return NULL;
	}
}
Beispiel #19
0
LDExporterSetting *LDExporter::addGeometrySettings(void) const
{
	LDExporterSetting *pGroup = addSettingGroup(ls(_UC("LDXGeometry")));
	if (pGroup == NULL)
	{
		return NULL;
	}
	addPrimSubSetting(pGroup);
	addSeamWidthSetting(pGroup);
	addEdgesSettings(pGroup);
	return pGroup;
}
Beispiel #20
0
BOOL JpegOptionsDialog::doInitDialog(HWND /*hKbControl*/)
{
	int index;
	int i;

	quality = options->getQuality();
	hQualityField = GetDlgItem(hWindow, IDC_JPEG_QUAL_FIELD);
	hQualitySpin = GetDlgItem(hWindow, IDC_JPEG_QUAL_SPIN);
	hQualitySlider = GetDlgItem(hWindow, IDC_JPEG_QUAL_SLIDER);
	trackBarSetup(IDC_JPEG_QUAL_SLIDER, 1, 100, 10, quality);
	for (i = 10; i < 100; i += 10)
	{
		trackBarSetTic(IDC_JPEG_QUAL_SLIDER, i);
	}
	textFieldSetLimitText(IDC_JPEG_QUAL_FIELD, 3);
	upDownSetup(IDC_JPEG_QUAL_SPIN, 1, 100, quality);
	setQuality(quality);
	comboAddString(IDC_JPEG_SUBSAMPLING_COMBO,
		ls(_UC("Jpeg444ss")));
	comboAddString(IDC_JPEG_SUBSAMPLING_COMBO,
		ls(_UC("Jpeg422ss")));
	comboAddString(IDC_JPEG_SUBSAMPLING_COMBO,
		ls(_UC("Jpeg420ss")));
	switch (options->getSubSampling())
	{
	case TCJpegOptions::SS422:
		index = 1;
		break;
	case TCJpegOptions::SS420:
		index = 2;
		break;
	default:	// TCJpegOptions::SS444
		index = 0;
		break;
	}
	comboSetCurSel(IDC_JPEG_SUBSAMPLING_COMBO, index);
	checkSet(IDC_JPEG_PROGRESSIVE_CHECK, options->getProgressive());
	return TRUE;
}
Beispiel #21
0
void SSPassword::loadPasswordDLL(void)
{
	HKEY hKey;

	if (runningOnNT)
	{
		return;
	}

	if (hInstPwdDLL)
	{
		unloadPasswordDLL();
	}

	// look in registry to see if password turned on, otherwise don't
	// bother to load password handler DLL
	if (RegOpenKey(HKEY_CURRENT_USER, REGSTR_PATH_SCREENSAVE, &hKey) ==
		ERROR_SUCCESS)
	{
		DWORD dwVal,dwSize=sizeof(dwVal);

		if ((RegQueryValueEx(hKey, REGSTR_VALUE_USESCRPASSWORD,
			NULL,NULL,(BYTE *) &dwVal,&dwSize) == ERROR_SUCCESS)
			&& dwVal)
		{

			// try to load the DLL that contains password proc.
			hInstPwdDLL = LoadLibrary(_UC("PASSWORD.CPL"));
			if (hInstPwdDLL)
			{
				verifyPasswordProc = (VERIFYPWDPROC) GetProcAddress(hInstPwdDLL,
					"VerifyScreenSavePwd");

				if (verifyPasswordProc)
				{
					hogMachine(TRUE);
				}
				else
				{
					unloadPasswordDLL();
				}
			}
		}

		RegCloseKey(hKey);
	}
}
Beispiel #22
0
bool LDLQuadLine::parse(void)
{
	float x1, y1, z1;
	float x2, y2, z2;
	float x3, y3, z3;
	float x4, y4, z4;
	int lineType;

	if (sscanf(m_line, "%d %i %f %f %f %f %f %f %f %f %f %f %f %f", &lineType,
		&m_colorNumber, &x1, &y1, &z1, &x2, &y2, &z2, &x3, &y3, &z3,
		&x4, &y4, &z4) == 14)
	{
		m_points = new TCVector[4];
		m_points[0] = TCVector(x1, y1, z1);
		m_points[1] = TCVector(x2, y2, z2);
		m_points[2] = TCVector(x3, y3, z3);
		m_points[3] = TCVector(x4, y4, z4);
		if (!getMainModel()->getSkipValidation())
		{
			// Note that we don't care what the second matching index is,
			// because we only need to throw out one of the two points, so don't
			// bother to even read it.
			if (getMatchingPoints(&m_matchingIndex))
			{
				m_valid = false;
			}
			else
			{
				swapPointsIfNeeded();
				checkForColinearPoints();
			}
		}
		return true;
	}
	else
	{
		m_valid = false;
		setError(LDLEParse, TCLocalStrings::get(_UC("LDLQuadLineParse")));
		return false;
	}
}
Beispiel #23
0
int LDExporter::runInternal(LDExporter *pExporter)
{
	int retValue;

	if (pExporter != NULL)
	{
		std::string filename = getFilename();

		if (filename.size() > 0)
		{
			LDLMainModel *pMainModel = new LDLMainModel;

			if (pMainModel->load(filename.c_str()))
			{
				char *cameraGlobe = stringForKey("CameraGlobe", NULL, false);
				LDLCamera camera;
				LDLAutoCamera *pAutoCamera = new LDLAutoCamera;

				pMainModel->getBoundingBox(pExporter->m_boundingMin,
					pExporter->m_boundingMax);
				pExporter->m_center = (pExporter->m_boundingMin +
					pExporter->m_boundingMax) / 2.0f;
				pExporter->m_radius =
					pMainModel->getMaxRadius(pExporter->m_center, true);
				pAutoCamera->setModel(pMainModel);
				pAutoCamera->setModelCenter(pExporter->m_center);
				pAutoCamera->setRotationMatrix(m_rotationMatrix);
				pAutoCamera->setCamera(camera);
				pAutoCamera->setCameraGlobe(cameraGlobe);
				//pAutoCamera->setDistanceMultiplier(distanceMultiplier);
				// Width and height are only needed for aspect ratio, not
				// absolute size.
				pAutoCamera->setWidth(m_width);
				pAutoCamera->setHeight(m_height);
				pAutoCamera->setFov(m_fov);
				pAutoCamera->setScanConditionalControlPoints(false);

				pAutoCamera->zoomToFit();
				pExporter->m_camera = pAutoCamera->getCamera();
				pAutoCamera->release();
				retValue = pExporter->doExport(pMainModel);
			}
			else
			{
#ifdef TC_NO_UNICODE
				consolePrintf(ls(_UC("ErrorLoadingModel")), filename.c_str());
#else // TC_NO_UNICODE
				std::wstring wfilename;
				stringtowstring(wfilename, filename);
				consolePrintf(ls(_UC("LDXErrorLoadingModel")), wfilename.c_str());
#endif // TC_NO_UNICODE
				retValue = 1;
			}
			TCObject::release(pMainModel);
		}
		else
		{
			consolePrintf(ls(_UC("LDXNoFilename")));
			retValue = 1;
		}
	}
	else
	{
		consolePrintf(ls(_UC("LDXUnknownOutputType")));
		retValue = 1;
	}
	return retValue;
}
Beispiel #24
0
void LDExporter::addConditionalEdgesSetting(LDExporterSetting *pGroup) const
{
	addSetting(pGroup, LDExporterSetting(ls(_UC("LDXConditionalEdges")),
		m_conditionalEdges, udKey("ConditionalEdges").c_str()));
}
Beispiel #25
0
bool LDLQuadLine::swapNeeded(int index1, int index2, int index3, int index4)
{
	TCVector &p1 = m_points[index1];
	TCVector &p2 = m_points[index2];
	TCVector &p3 = m_points[index3];
	TCVector &p4 = m_points[index4];
	TCVector normal1 = (p1 - p4) * (p1 - p2);
	TCVector normal2 = (p2 - p1) * (p2 - p3);
	TCVector normal3 = (p3 - p2) * (p3 - p4);
	TCVector normal4 = (p4 - p3) * (p4 - p1);
	TCFloat length1 = normal1.length();
	TCFloat length2 = normal2.length();
	TCFloat length3 = normal3.length();
	TCFloat length4 = normal4.length();
	TCFloat dotProduct;
	bool nonFlat = false;

	if (fEq(length1, 0.0) || fEq(length2, 0.0) ||
		fEq(length3, 0.0) || fEq(length4, 0.0))
	{
		return false;
	}
	normal1 /= length1;
	normal2 /= length2;
	normal3 /= length3;
	normal4 /= length4;
	if ((dotProduct = normal1.dot(normal2)) <= 0.0)
	{
		return true;
	}
	if (dotProduct <= 0.9)
	{
		nonFlat = true;
	}
	if ((dotProduct = normal1.dot(normal3)) <= 0.0)
	{
		return true;
	}
	if (dotProduct <= 0.9)
	{
		nonFlat = true;
	}
	if ((dotProduct = normal1.dot(normal4)) <= 0.0)
	{
		return true;
	}
	if (dotProduct <= 0.9)
	{
		nonFlat = true;
	}
	if ((dotProduct = normal2.dot(normal3)) <= 0.0)
	{
		return true;
	}
	if (dotProduct <= 0.9)
	{
		nonFlat = true;
	}
	if ((dotProduct = normal2.dot(normal4)) <= 0.0)
	{
		return true;
	}
	if (dotProduct <= 0.9)
	{
		nonFlat = true;
	}
	if ((dotProduct = normal3.dot(normal4)) <= 0.0)
	{
		return true;
	}
	if (dotProduct <= 0.9)
	{
		nonFlat = true;
	}
	if (nonFlat)
	{
		setWarning(LDLENonFlatQuad,
			TCLocalStrings::get(_UC("LDLQuadLineNonFlatError")));
	}
	return false;
}
bool TCJpegImageFormat::saveFile(TCImage *image, FILE *file)
{
	bool retValue = false;
	bool canceled = false;
	struct jpeg_compress_struct cinfo;
	struct jpeg_error_mgr jerr;

	if (image->getDataFormat() != TCRgb8 && image->getDataFormat() != TCRgba8)
	{
		return false;
	}
	if (setup(cinfo, jerr))
	{
		std::vector<TCByte> row;
		TCByte *imageData;
		int rowSize;
		int offset = 0;
		int dir = 1;
		TCByte *rowBytes = NULL;
		TCJpegOptions *options =
			(TCJpegOptions *)image->getCompressionOptions();

		imageWidth = image->getWidth();
		imageHeight = image->getHeight();
		this->image = image;
		// WARNING: Do NOT put any C++ objects that need destructors inside the
		// following if statement.  Doing so will result in a memory leak if any
		// error occurs.
#ifdef WIN32
#pragma warning( push )
#pragma warning( disable : 4611 )
#endif // WIN32
		if (setjmp(jumpBuf))
#ifdef WIN32
#pragma warning( pop )
#endif // WIN32
		{
			// If we get here, there was an error below.
			// Note: jpeg_destroy_compress is called automatically by the JPEG
			// library error handling code.  We really are good to just exit.
			return false;
		}
		jpeg_stdio_dest(&cinfo, file);
		callProgressCallback(_UC("SavingJPG"), 0.0f);
		cinfo.in_color_space = JCS_RGB;
		cinfo.image_width = imageWidth;
		cinfo.image_height = image->getHeight();
		cinfo.input_components = 3;
		imageData = image->getImageData();
		rowSize = image->getRowSize();
		if (image->getFlipped())
		{
			offset = rowSize * (imageHeight - 1);
			dir = -1;
		}
		if (image->getDataFormat() == TCRgba8)
		{
			row.resize(image->getWidth() * 3);
			rowBytes = &row[0];
		}
		jpeg_set_defaults(&cinfo);
		jpeg_default_colorspace(&cinfo);
		jpeg_set_quality(&cinfo, options->getQuality(), FALSE);
		switch (options->getSubSampling())
		{
		case TCJpegOptions::SS420:
			// 4:2:0
			cinfo.comp_info[0].h_samp_factor = 2;
			cinfo.comp_info[0].v_samp_factor = 2;
			cinfo.comp_info[1].h_samp_factor = 1;
			cinfo.comp_info[1].v_samp_factor = 1;
			cinfo.comp_info[2].h_samp_factor = 1;
			cinfo.comp_info[2].v_samp_factor = 1;
			break;
		case TCJpegOptions::SS422:
			// 4:2:2
			cinfo.comp_info[0].h_samp_factor = 2;
			cinfo.comp_info[0].v_samp_factor = 1;
			cinfo.comp_info[1].h_samp_factor = 1;
			cinfo.comp_info[1].v_samp_factor = 1;
			cinfo.comp_info[2].h_samp_factor = 1;
			cinfo.comp_info[2].v_samp_factor = 1;
			break;
		case TCJpegOptions::SS444:
			// 4:4:4
			cinfo.comp_info[0].h_samp_factor = 1;
			cinfo.comp_info[0].v_samp_factor = 1;
			cinfo.comp_info[1].h_samp_factor = 1;
			cinfo.comp_info[1].v_samp_factor = 1;
			cinfo.comp_info[2].h_samp_factor = 1;
			cinfo.comp_info[2].v_samp_factor = 1;
			break;
		}
		if (options->getProgressive())
		{
			jpeg_simple_progression(&cinfo);
		}
		jpeg_start_compress(&cinfo, TRUE);
		while (cinfo.next_scanline < cinfo.image_height && !canceled)
		{
			unsigned int result;

			if (image->getDataFormat() == TCRgb8)
			{
				rowBytes = &imageData[offset];
			}
			else
			{
				int dstIndex = 0;
				int srcIndex = offset;

				// Convert RGBA to RGB.
				for (unsigned int x = 0; x < imageWidth; x++)
				{
					rowBytes[dstIndex++] = imageData[srcIndex++];
					rowBytes[dstIndex++] = imageData[srcIndex++];
					rowBytes[dstIndex++] = imageData[srcIndex++];
					srcIndex++;
				}
			}
			result = jpeg_write_scanlines(&cinfo, &rowBytes, 1);
			offset += result * rowSize * dir;
			if (!callProgressCallback(NULL, (float)cinfo.next_scanline /
				(float)cinfo.image_height))
			{
				canceled = true;
			}
		}
		if (canceled)
		{
			jpeg_abort_compress(&cinfo);
		}
		else
		{
			jpeg_finish_compress(&cinfo);
			retValue = true;
		}
		jpeg_destroy_compress(&cinfo);
	}
	callProgressCallback(NULL, 2.0f);
	return retValue && !canceled;
}
bool TCJpegImageFormat::loadFile(TCImage *image, FILE *file)
{
	bool retValue = false;
	bool canceled = false;
	struct jpeg_decompress_struct cinfo;
	struct jpeg_error_mgr jerr;

	if (setup(cinfo, jerr))
	{
		std::vector<TCByte> grayRow;

		this->image = image;
		jpeg_stdio_src(&cinfo, file);
		// WARNING: Do NOT put any C++ objects that need destructors inside the
		// following if statement.  Doing so will result in a memory leak if any
		// error occurs.
#ifdef WIN32
#pragma warning( push )
#pragma warning( disable : 4611 )
#endif // WIN32
		if (setjmp(jumpBuf))
#ifdef WIN32
#pragma warning( pop )
#endif // WIN32
		{
			// If we get here, there was an error below.
			// Note: jpeg_destroy_decompress is called automatically by the JPEG
			// library error handling code.  We really are good to just exit.
			return false;
		}
		callProgressCallback(_UC("LoadingJPG"), 0.0f);
		if (jpeg_read_header(&cinfo, TRUE) == JPEG_HEADER_OK)
		{
			cinfo.output_components = 3;
			cinfo.out_color_space = JCS_RGB;
			if (jpeg_start_decompress(&cinfo))
			{
				if ((cinfo.out_color_space == JCS_RGB ||
					cinfo.out_color_space == JCS_GRAYSCALE) &&
					(cinfo.output_components == 3 ||
					cinfo.output_components == 1))
				{
					TCByte *imageData;
					int rowSize;
					int offset = 0;
					int dir = 1;

					imageWidth = cinfo.output_width;
					imageHeight = cinfo.output_height;
					if (cinfo.output_components != 3)
					{
						grayRow.resize(imageWidth * cinfo.output_components);
					}
					image->setDataFormat(TCRgb8);
					image->setSize(imageWidth, imageHeight);
					image->allocateImageData();
					rowSize = image->getRowSize();
					imageData = image->getImageData();
					if (image->getFlipped())
					{
						offset = rowSize * (imageHeight - 1);
						dir = -1;
					}
					while (cinfo.output_scanline < cinfo.output_height &&
						!canceled)
					{
						unsigned int result;

						if (cinfo.output_components == 1)
						{
							unsigned char *grayBytes = &grayRow[0];
							// grayscale
							result = jpeg_read_scanlines(&cinfo, &grayBytes, 1);
							for (unsigned int i = 0; i < imageWidth; i++)
							{
								TCByte value = grayRow[i];

								imageData[offset + i * 3] = value;
								imageData[offset + i * 3 + 1] = value;
								imageData[offset + i * 3 + 2] = value;
							}
						}
						else
						{
							unsigned char *rowBytes = &imageData[offset];
							result = jpeg_read_scanlines(&cinfo, &rowBytes,
								1);
						}
						offset += result * rowSize * dir;
						if (!callProgressCallback(NULL, (float)cinfo.output_scanline /
							(float)cinfo.output_height))
						{
							canceled = true;
						}
					}
					retValue = true;
				}
			}
		}
		if (retValue && !canceled)
		{
			if (!jpeg_finish_decompress(&cinfo))
			{
				retValue = false;
			}
		}
		else
		{
			jpeg_abort_decompress(&cinfo);
		}
		jpeg_destroy_decompress(&cinfo);
	}
	callProgressCallback(NULL, 2.0f);
	return retValue && !canceled;
}
Beispiel #28
0
ucstring LDExporter::getTypeDescription(void) const
{
	consolePrintf("Programmer error: LDExporter::getTypeDescription called.\n");
	return _UC("");
}
Beispiel #29
0
bool LDLMainModel::load(const char *filename)
{
	FILE *file;
	LDLError *error;

	setFilename(filename);
	lDrawDir();	// Initializes sm_lDrawIni
	if (sm_lDrawIni)
	{
		LDrawIniComputeRealDirs(sm_lDrawIni, 1, 0, filename);
	}
	if (!strlen(lDrawDir()))
	{
		error = newError(LDLEGeneral,
			TCLocalStrings::get(_UC("LDLMainModelNoLDrawDir")));
		error->setLevel(LDLACriticalError);
		sendAlert(error);
		error->release();
		return false;
	}
	file = fopen(filename, "rb");
	m_mainModel = this;
	if (file)
	{
		bool retValue;

		if (m_mainFlags.processLDConfig)
		{
			processLDConfig();
		}
		retValue = LDLModel::load(file);
		if (sm_lDrawIni)
		{
			// If bool isn't 1 byte, then the filename case callback won't
			// work, so doesn't get used.  Check to see if this will be a
			// problem.
			if (sizeof(bool) != sizeof(char) && fileCaseCallback)
			{
				char *tmpStr;
				size_t len = strlen(lDrawDir());
				bool failed = false;
				struct stat statData;

				tmpStr = new char[len + 10];
				sprintf(tmpStr, "%s/P", lDrawDir());
				if (stat(tmpStr, &statData) != 0)
				{
					// Check to see if we can access the P directory inside the
					// LDraw directory.  If not, then we have a problem that
					// needs to be reported to the user.
					failed = true;
				}
				if (!failed)
				{
					sprintf(tmpStr, "%s/PARTS", lDrawDir());
					if (stat(tmpStr, &statData) != 0)
					{
						// Check to see if we can access the PARTS directory
						// inside the LDraw directory.  If not, then we have a
						// problem that needs to be reported to the user.
						failed = true;
					}
				}
				delete tmpStr;
				if (failed)
				{
					// Either P or PARTS was inaccessible, so let the user
					// know that they need to rename the directories to be in
					// upper case.
					reportError(LDLEGeneral,
						TCLocalStrings::get(_UC("LDLMainModelFileCase")));
				}
			}
		}
		// The ancestor map has done its job; may as well free up the memory it
		// was using.
		m_ancestorMap.clear();
		return retValue;
	}
	else
	{
		error = newError(LDLEFileNotFound,
			TCLocalStrings::get(_UC("LDLMainModelNoMainModel")));
		error->setLevel(LDLACriticalError);
		sendAlert(error);
		error->release();
		return false;
	}
}
Beispiel #30
0
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/,
				   LPSTR lpCmdLine, int nCmdShow)
{
	ModelLoader* modelLoader;
	bool screenSaver = isScreenSaver();
	int retValue;
	STARTUPINFO startupInfo;
	bool fromConsole = false;

	//HMODULE hThumbs = LoadLibrary("LDViewThumbs.dll");
	//if (hThumbs != NULL)
	//{
	//	PFNDLLREGISTERSERVER pDllRegisterServer =
	//		(PFNDLLREGISTERSERVER)GetProcAddress(hThumbs, "DllRegisterServer");

	//	CoInitialize(NULL);
	//	if (pDllRegisterServer != NULL)
	//	{
	//		pDllRegisterServer();
	//	}
	//}
	memset(&startupInfo, 0, sizeof(startupInfo));
	startupInfo.cb = sizeof(startupInfo);
	GetStartupInfo(&startupInfo);
	if (startupInfo.lpTitle != NULL &&
		stringHasCaseInsensitivePrefix(startupInfo.lpTitle, "command line ")
		&& strcasestr(startupInfo.lpTitle, "ldview") != NULL)
	{
		runningWithConsole();
		fromConsole = true;
	}
#ifdef _DEBUG
	int _debugFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
	_debugFlag |= _CRTDBG_LEAK_CHECK_DF;
	_CrtSetDbgFlag(_debugFlag);
	_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG);
	if (!fromConsole)
	{
		createConsole();
	}
//	MessageBox(NULL, "Attach a debugger now...", "Debug", MB_OK);
#endif // _DEBUG
	bool udok = setupUserDefaults(lpCmdLine, screenSaver,
		isRemovableDrive(hInstance));
	setupLocalStrings();
	if (TCUserDefaults::boolForKey(DEBUG_COMMAND_LINE_KEY, false, false))
	{
		std::string message = "Command Line:\n";

		message += lpCmdLine;
		MessageBox(NULL, message.c_str(), "LDView", MB_OK);
	}
	if (!udok && !TCUserDefaults::longForKey("IniFailureShown", 0, 0))
	{
		UCCHAR message[2048];
		UCSTR iniPath = mbstoucstring(TCUserDefaults::getIniPath());

		sucprintf(message, COUNT_OF(message),
			TCLocalStrings::get(_UC("IniFailure")), iniPath);
		CUIWindow::messageBoxUC(NULL, message, _UC("LDView"), MB_OK);
		delete iniPath;
		TCUserDefaults::setLongForKey(1, "IniFailureShown", false);
	}
	if (screenSaver)
	{
		if (strncasecmp(lpCmdLine, "/p", 2) == 0 ||
			strncasecmp(lpCmdLine, "-p", 2) == 0 ||
			strncasecmp(lpCmdLine, "p", 1) == 0)
		{
			// preview mode
			return doPreview(hInstance, lpCmdLine);
		}
		if (strncasecmp(lpCmdLine, "/c", 2) == 0 ||
			strncasecmp(lpCmdLine, "-c", 2) == 0 ||
			strncasecmp(lpCmdLine, "c", 1) == 0 ||
			strlen(lpCmdLine) == 0)
		{
			SSConfigure *configure;

			configure = new SSConfigure(hInstance);
#ifdef _DEBUG
			_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG);
			createConsole();
#endif // _DEBUG
			configure->run();
			// configure mode
			return 1;
		}
		// This shouldn't be necessary, but I've received a report of a whole
		// bunch of copies of the LDView screensaver running at once.  This
		// might not fix things entirely, but it will at least prevent it
		// from launching multiple times concurrently.
		CreateMutex(NULL, FALSE, "LDView Screensaver");
		if (GetLastError() == ERROR_ALREADY_EXISTS)
		{
			return 0;
		}
	}
#ifdef _LOG_PERFORMANCE
	LARGE_INTEGER frequency;
	if (QueryPerformanceFrequency(&frequency))
	{
		debugPrintf("Frequency: %I64d\n", frequency.QuadPart);
	}
#endif // _LOG_PERFORMANCE
	OleInitialize(NULL);

	//Win7JumpListStuff();

	modelLoader = new ModelLoader(CUIWindow::getLanguageModule(), nCmdShow,
		screenSaver);
	retValue = mainLoop();
	modelLoader->release();
	return retValue;
} // WinMain