mirror of
https://github.com/leozide/leocad
synced 2024-12-26 21:58:44 +01:00
Use QString for object names.
This commit is contained in:
parent
1012fc20cd
commit
2d7aba8895
13 changed files with 77 additions and 62 deletions
|
@ -68,17 +68,22 @@ void lcCamera::Initialize()
|
||||||
m_zNear = 25.0f;
|
m_zNear = 25.0f;
|
||||||
m_zFar = 50000.0f;
|
m_zFar = 50000.0f;
|
||||||
mState = 0;
|
mState = 0;
|
||||||
memset(m_strName, 0, sizeof(m_strName));
|
}
|
||||||
|
|
||||||
|
void lcCamera::SetName(const QString& Name)
|
||||||
|
{
|
||||||
|
mName = Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcCamera::CreateName(const lcArray<lcCamera*>& Cameras)
|
void lcCamera::CreateName(const lcArray<lcCamera*>& Cameras)
|
||||||
{
|
{
|
||||||
if (m_strName[0])
|
if (!mName.isEmpty())
|
||||||
{
|
{
|
||||||
bool Found = false;
|
bool Found = false;
|
||||||
for (int CameraIdx = 0; CameraIdx < Cameras.GetSize(); CameraIdx++)
|
|
||||||
|
for (const lcCamera* Camera : Cameras)
|
||||||
{
|
{
|
||||||
if (!strcmp(Cameras[CameraIdx]->m_strName, m_strName))
|
if (Camera->GetName() == mName)
|
||||||
{
|
{
|
||||||
Found = true;
|
Found = true;
|
||||||
break;
|
break;
|
||||||
|
@ -89,16 +94,24 @@ void lcCamera::CreateName(const lcArray<lcCamera*>& Cameras)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int i, max = 0;
|
int MaxCameraNumber = 0;
|
||||||
const char* Prefix = "Camera ";
|
const QLatin1String Prefix("Camera ");
|
||||||
|
|
||||||
for (int CameraIdx = 0; CameraIdx < Cameras.GetSize(); CameraIdx++)
|
for (const lcCamera* Camera : Cameras)
|
||||||
if (strncmp(Cameras[CameraIdx]->m_strName, Prefix, strlen(Prefix)) == 0)
|
{
|
||||||
if (sscanf(Cameras[CameraIdx]->m_strName + strlen(Prefix), " %d", &i) == 1)
|
QString CameraName = Camera->GetName();
|
||||||
if (i > max)
|
|
||||||
max = i;
|
|
||||||
|
|
||||||
sprintf(m_strName, "%s %d", Prefix, max+1);
|
if (CameraName.startsWith(Prefix))
|
||||||
|
{
|
||||||
|
bool Ok = false;
|
||||||
|
int CameraNumber = CameraName.midRef(Prefix.size()).toInt(&Ok);
|
||||||
|
|
||||||
|
if (Ok && CameraNumber > MaxCameraNumber)
|
||||||
|
MaxCameraNumber = CameraNumber;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mName = Prefix + QString::number(MaxCameraNumber + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcCamera::SaveLDraw(QTextStream& Stream) const
|
void lcCamera::SaveLDraw(QTextStream& Stream) const
|
||||||
|
@ -130,7 +143,7 @@ void lcCamera::SaveLDraw(QTextStream& Stream) const
|
||||||
if (IsOrtho())
|
if (IsOrtho())
|
||||||
Stream << QLatin1String("ORTHOGRAPHIC ");
|
Stream << QLatin1String("ORTHOGRAPHIC ");
|
||||||
|
|
||||||
Stream << QLatin1String("NAME ") << m_strName << LineEnding;
|
Stream << QLatin1String("NAME ") << mName << LineEnding;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lcCamera::ParseLDrawLine(QTextStream& Stream)
|
bool lcCamera::ParseLDrawLine(QTextStream& Stream)
|
||||||
|
@ -173,10 +186,7 @@ bool lcCamera::ParseLDrawLine(QTextStream& Stream)
|
||||||
LoadKeysLDraw(Stream, mUpVectorKeys);
|
LoadKeysLDraw(Stream, mUpVectorKeys);
|
||||||
else if (Token == QLatin1String("NAME"))
|
else if (Token == QLatin1String("NAME"))
|
||||||
{
|
{
|
||||||
QString Name = Stream.readAll().trimmed();
|
mName = Stream.readAll().trimmed();
|
||||||
QByteArray NameUtf = Name.toUtf8(); // todo: replace with qstring
|
|
||||||
strncpy(m_strName, NameUtf.constData(), sizeof(m_strName));
|
|
||||||
m_strName[sizeof(m_strName) - 1] = 0;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -232,16 +242,20 @@ bool lcCamera::FileLoad(lcFile& file)
|
||||||
|
|
||||||
if (version == 4)
|
if (version == 4)
|
||||||
{
|
{
|
||||||
file.ReadBuffer(m_strName, 80);
|
char Name[81];
|
||||||
m_strName[80] = 0;
|
file.ReadBuffer(Name, 80);
|
||||||
|
Name[80] = 0;
|
||||||
|
mName = Name;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ch = file.ReadU8();
|
ch = file.ReadU8();
|
||||||
if (ch == 0xFF)
|
if (ch == 0xFF)
|
||||||
return false; // don't read CString
|
return false; // don't read CString
|
||||||
file.ReadBuffer(m_strName, ch);
|
char Name[81];
|
||||||
m_strName[ch] = 0;
|
file.ReadBuffer(Name, ch);
|
||||||
|
Name[ch] = 0;
|
||||||
|
mName = Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (version < 3)
|
if (version < 3)
|
||||||
|
|
|
@ -47,11 +47,12 @@ public:
|
||||||
lcCamera& operator=(const lcCamera&) = delete;
|
lcCamera& operator=(const lcCamera&) = delete;
|
||||||
lcCamera& operator=(lcCamera&&) = delete;
|
lcCamera& operator=(lcCamera&&) = delete;
|
||||||
|
|
||||||
const char* GetName() const override
|
QString GetName() const override
|
||||||
{
|
{
|
||||||
return m_strName;
|
return mName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetName(const QString& Name);
|
||||||
void CreateName(const lcArray<lcCamera*>& Cameras);
|
void CreateName(const lcArray<lcCamera*>& Cameras);
|
||||||
|
|
||||||
bool IsSimple() const
|
bool IsSimple() const
|
||||||
|
@ -294,8 +295,6 @@ public:
|
||||||
void GetAngles(float& Latitude, float& Longitude, float& Distance) const;
|
void GetAngles(float& Latitude, float& Longitude, float& Distance) const;
|
||||||
void SetAngles(float Latitude, float Longitude, float Distance);
|
void SetAngles(float Latitude, float Longitude, float Distance);
|
||||||
|
|
||||||
char m_strName[81];
|
|
||||||
|
|
||||||
float m_fovy;
|
float m_fovy;
|
||||||
float m_zNear;
|
float m_zNear;
|
||||||
float m_zFar;
|
float m_zFar;
|
||||||
|
@ -312,6 +311,6 @@ protected:
|
||||||
|
|
||||||
void Initialize();
|
void Initialize();
|
||||||
|
|
||||||
|
QString mName;
|
||||||
quint32 mState;
|
quint32 mState;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -369,13 +369,13 @@ void lcGLWidget::SetCamera(lcCamera* Camera, bool ForceCopy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcGLWidget::SetCamera(const char* CameraName)
|
void lcGLWidget::SetCamera(const QString& CameraName)
|
||||||
{
|
{
|
||||||
const lcArray<lcCamera*>& Cameras = mModel->GetCameras();
|
const lcArray<lcCamera*>& Cameras = mModel->GetCameras();
|
||||||
|
|
||||||
for (int CameraIdx = 0; CameraIdx < Cameras.GetSize(); CameraIdx++)
|
for (int CameraIdx = 0; CameraIdx < Cameras.GetSize(); CameraIdx++)
|
||||||
{
|
{
|
||||||
if (qstricmp(CameraName, Cameras[CameraIdx]->m_strName) == 0)
|
if (CameraName.compare(Cameras[CameraIdx]->GetName(), Qt::CaseInsensitive) == 0)
|
||||||
{
|
{
|
||||||
SetCameraIndex(CameraIdx);
|
SetCameraIndex(CameraIdx);
|
||||||
return;
|
return;
|
||||||
|
@ -557,9 +557,9 @@ void lcGLWidget::DrawViewport() const
|
||||||
mContext->SetVertexFormatPosition(2);
|
mContext->SetVertexFormatPosition(2);
|
||||||
mContext->DrawPrimitives(GL_LINE_LOOP, 0, 4);
|
mContext->DrawPrimitives(GL_LINE_LOOP, 0, 4);
|
||||||
|
|
||||||
const char* CameraName = mCamera->GetName();
|
QString CameraName = mCamera->GetName();
|
||||||
|
|
||||||
if (CameraName[0])
|
if (!CameraName.isEmpty())
|
||||||
{
|
{
|
||||||
mContext->SetMaterial(lcMaterialType::UnlitTextureModulate);
|
mContext->SetMaterial(lcMaterialType::UnlitTextureModulate);
|
||||||
mContext->SetColor(0.0f, 0.0f, 0.0f, 1.0f);
|
mContext->SetColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
|
@ -567,7 +567,7 @@ void lcGLWidget::DrawViewport() const
|
||||||
|
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
|
|
||||||
gTexFont.PrintText(mContext, 3.0f, (float)mHeight - 1.0f - 6.0f, 0.0f, CameraName);
|
gTexFont.PrintText(mContext, 3.0f, (float)mHeight - 1.0f - 6.0f, 0.0f, CameraName.toLatin1().constData());
|
||||||
|
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,7 +165,7 @@ public:
|
||||||
void SetCameraAngles(float Latitude, float Longitude);
|
void SetCameraAngles(float Latitude, float Longitude);
|
||||||
void SetDefaultCamera();
|
void SetDefaultCamera();
|
||||||
void SetCamera(lcCamera* Camera, bool ForceCopy);
|
void SetCamera(lcCamera* Camera, bool ForceCopy);
|
||||||
void SetCamera(const char* CameraName);
|
void SetCamera(const QString& CameraName);
|
||||||
void SetCameraIndex(int Index);
|
void SetCameraIndex(int Index);
|
||||||
|
|
||||||
void DrawBackground() const;
|
void DrawBackground() const;
|
||||||
|
|
|
@ -1392,7 +1392,7 @@ QByteArray lcMainWindow::GetTabLayout()
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DataStream << (qint32)1;
|
DataStream << (qint32)1;
|
||||||
DataStream << QByteArray::fromRawData(Camera->m_strName, sizeof(Camera->m_strName));
|
DataStream << Camera->GetName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -3022,13 +3022,12 @@ void lcModel::SetCameraZFar(lcCamera* Camera, float ZFar)
|
||||||
gMainWindow->UpdateAllViews();
|
gMainWindow->UpdateAllViews();
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcModel::SetCameraName(lcCamera* Camera, const char* Name)
|
void lcModel::SetCameraName(lcCamera* Camera, const QString& Name)
|
||||||
{
|
{
|
||||||
if (!strcmp(Camera->m_strName, Name))
|
if (Camera->GetName() == Name)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
strncpy(Camera->m_strName, Name, sizeof(Camera->m_strName));
|
Camera->SetName(Name);
|
||||||
Camera->m_strName[sizeof(Camera->m_strName) - 1] = 0;
|
|
||||||
|
|
||||||
SaveCheckpoint(tr("Renaming Camera"));
|
SaveCheckpoint(tr("Renaming Camera"));
|
||||||
gMainWindow->UpdateSelectedObjects(false);
|
gMainWindow->UpdateSelectedObjects(false);
|
||||||
|
@ -3857,7 +3856,7 @@ void lcModel::FindPiece(bool FindFirst, bool SearchForward)
|
||||||
|
|
||||||
if ((!SearchOptions.MatchInfo || Current->mPieceInfo == SearchOptions.Info) &&
|
if ((!SearchOptions.MatchInfo || Current->mPieceInfo == SearchOptions.Info) &&
|
||||||
(!SearchOptions.MatchColor || Current->mColorIndex == SearchOptions.ColorIndex) &&
|
(!SearchOptions.MatchColor || Current->mColorIndex == SearchOptions.ColorIndex) &&
|
||||||
(!SearchOptions.MatchName || strcasestr(Current->GetName(), SearchOptions.Name)))
|
(!SearchOptions.MatchName || (Current->GetName().indexOf(SearchOptions.Name, 0, Qt::CaseInsensitive) != -1)))
|
||||||
{
|
{
|
||||||
Focus = Current;
|
Focus = Current;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -340,7 +340,7 @@ public:
|
||||||
void SetCameraFOV(lcCamera* Camera, float FOV);
|
void SetCameraFOV(lcCamera* Camera, float FOV);
|
||||||
void SetCameraZNear(lcCamera* Camera, float ZNear);
|
void SetCameraZNear(lcCamera* Camera, float ZNear);
|
||||||
void SetCameraZFar(lcCamera* Camera, float ZFar);
|
void SetCameraZFar(lcCamera* Camera, float ZFar);
|
||||||
void SetCameraName(lcCamera* Camera, const char* Name);
|
void SetCameraName(lcCamera* Camera, const QString& Name);
|
||||||
|
|
||||||
void ShowPropertiesDialog();
|
void ShowPropertiesDialog();
|
||||||
void ShowSelectByNameDialog();
|
void ShowSelectByNameDialog();
|
||||||
|
|
|
@ -32,7 +32,6 @@ lcLight::lcLight(float px, float py, float pz, float tx, float ty, float tz)
|
||||||
void lcLight::Initialize(const lcVector3& Position, const lcVector3& TargetPosition)
|
void lcLight::Initialize(const lcVector3& Position, const lcVector3& TargetPosition)
|
||||||
{
|
{
|
||||||
mState = 0;
|
mState = 0;
|
||||||
memset(m_strName, 0, sizeof(m_strName));
|
|
||||||
|
|
||||||
ChangeKey(mPositionKeys, Position, 1, true);
|
ChangeKey(mPositionKeys, Position, 1, true);
|
||||||
ChangeKey(mTargetPositionKeys, TargetPosition, 1, true);
|
ChangeKey(mTargetPositionKeys, TargetPosition, 1, true);
|
||||||
|
@ -55,13 +54,13 @@ void lcLight::SaveLDraw(QTextStream& Stream) const
|
||||||
|
|
||||||
void lcLight::CreateName(const lcArray<lcLight*>& Lights)
|
void lcLight::CreateName(const lcArray<lcLight*>& Lights)
|
||||||
{
|
{
|
||||||
if (m_strName[0])
|
if (!mName.isEmpty())
|
||||||
{
|
{
|
||||||
bool Found = false;
|
bool Found = false;
|
||||||
|
|
||||||
for (lcLight* Light : Lights)
|
for (lcLight* Light : Lights)
|
||||||
{
|
{
|
||||||
if (!strcmp(Light->m_strName, m_strName))
|
if (Light->GetName() == mName)
|
||||||
{
|
{
|
||||||
Found = true;
|
Found = true;
|
||||||
break;
|
break;
|
||||||
|
@ -72,21 +71,24 @@ void lcLight::CreateName(const lcArray<lcLight*>& Lights)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int i, max = 0;
|
int MaxLightNumber = 0;
|
||||||
|
const QLatin1String Prefix("Light ");
|
||||||
|
|
||||||
for (lcLight* Light : Lights)
|
for (lcLight* Light : Lights)
|
||||||
{
|
{
|
||||||
if (strncmp(Light->m_strName, "Light ", 6) == 0)
|
QString LightName = Light->GetName();
|
||||||
|
|
||||||
|
if (LightName.startsWith(Prefix))
|
||||||
{
|
{
|
||||||
if (sscanf(Light->m_strName + 6, " #%d", &i) == 1)
|
bool Ok = false;
|
||||||
{
|
int LightNumber = LightName.midRef(Prefix.size()).toInt(&Ok);
|
||||||
if (i > max)
|
|
||||||
max = i;
|
if (Ok && LightNumber > MaxLightNumber)
|
||||||
}
|
MaxLightNumber = LightNumber;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(m_strName, "Light #%.2d", max+1);
|
mName = Prefix + QString::number(MaxLightNumber + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcLight::CompareBoundingBox(lcVector3& Min, lcVector3& Max)
|
void lcLight::CompareBoundingBox(lcVector3& Min, lcVector3& Max)
|
||||||
|
|
|
@ -191,8 +191,10 @@ public:
|
||||||
bool IsVisible() const
|
bool IsVisible() const
|
||||||
{ return (mState & LC_LIGHT_HIDDEN) == 0; }
|
{ return (mState & LC_LIGHT_HIDDEN) == 0; }
|
||||||
|
|
||||||
const char* GetName() const override
|
QString GetName() const override
|
||||||
{ return m_strName; }
|
{
|
||||||
|
return mName;
|
||||||
|
}
|
||||||
|
|
||||||
void CompareBoundingBox(lcVector3& Min, lcVector3& Max);
|
void CompareBoundingBox(lcVector3& Min, lcVector3& Max);
|
||||||
void UpdatePosition(lcStep Step);
|
void UpdatePosition(lcStep Step);
|
||||||
|
@ -226,7 +228,6 @@ protected:
|
||||||
void DrawPointLight(lcContext* Context) const;
|
void DrawPointLight(lcContext* Context) const;
|
||||||
void DrawSpotLight(lcContext* Context) const;
|
void DrawSpotLight(lcContext* Context) const;
|
||||||
|
|
||||||
|
QString mName;
|
||||||
quint32 mState;
|
quint32 mState;
|
||||||
char m_strName[81];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ public:
|
||||||
virtual void BoxTest(lcObjectBoxTest& ObjectBoxTest) const = 0;
|
virtual void BoxTest(lcObjectBoxTest& ObjectBoxTest) const = 0;
|
||||||
virtual void DrawInterface(lcContext* Context, const lcScene& Scene) const = 0;
|
virtual void DrawInterface(lcContext* Context, const lcScene& Scene) const = 0;
|
||||||
virtual void RemoveKeyFrames() = 0;
|
virtual void RemoveKeyFrames() = 0;
|
||||||
virtual const char* GetName() const = 0;
|
virtual QString GetName() const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
|
@ -896,9 +896,9 @@ void lcPiece::VerifyControlPoints(lcArray<lcPieceControlPoint>& ControlPoints) c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* lcPiece::GetName() const
|
QString lcPiece::GetName() const
|
||||||
{
|
{
|
||||||
return mPieceInfo->m_strDescription;
|
return QString::fromLatin1(mPieceInfo->m_strDescription);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lcPiece::IsVisible(lcStep Step) const
|
bool lcPiece::IsVisible(lcStep Step) const
|
||||||
|
|
|
@ -453,7 +453,7 @@ public:
|
||||||
|
|
||||||
void UpdateID();
|
void UpdateID();
|
||||||
|
|
||||||
const char* GetName() const override;
|
QString GetName() const override;
|
||||||
bool IsVisible(lcStep Step) const;
|
bool IsVisible(lcStep Step) const;
|
||||||
bool IsVisibleInSubModel() const;
|
bool IsVisibleInSubModel() const;
|
||||||
void GetModelParts(const lcMatrix44& WorldMatrix, int DefaultColorIndex, std::vector<lcModelPartsEntry>& ModelParts) const;
|
void GetModelParts(const lcMatrix44& WorldMatrix, int DefaultColorIndex, std::vector<lcModelPartsEntry>& ModelParts) const;
|
||||||
|
|
|
@ -492,7 +492,7 @@ QWidget *lcQPropertiesTree::createEditor(QWidget *parent, QTreeWidgetItem *item)
|
||||||
case PropertyString:
|
case PropertyString:
|
||||||
{
|
{
|
||||||
QLineEdit *editor = new QLineEdit(parent);
|
QLineEdit *editor = new QLineEdit(parent);
|
||||||
const char *value = (const char*)item->data(0, PropertyValueRole).value<void*>();
|
QString value = item->data(0, PropertyValueRole).toString();
|
||||||
|
|
||||||
editor->setText(value);
|
editor->setText(value);
|
||||||
|
|
||||||
|
@ -740,7 +740,7 @@ void lcQPropertiesTree::slotReturnPressed()
|
||||||
{
|
{
|
||||||
QString Value = Editor->text();
|
QString Value = Editor->text();
|
||||||
|
|
||||||
Model->SetCameraName(Camera, Value.toLocal8Bit().data());
|
Model->SetCameraName(Camera, Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1062,7 +1062,7 @@ void lcQPropertiesTree::SetCamera(lcObject* Focus)
|
||||||
float FoV = 60.0f;
|
float FoV = 60.0f;
|
||||||
float ZNear = 1.0f;
|
float ZNear = 1.0f;
|
||||||
float ZFar = 100.0f;
|
float ZFar = 100.0f;
|
||||||
const char* Name = "";
|
QString Name;
|
||||||
|
|
||||||
if (Camera)
|
if (Camera)
|
||||||
{
|
{
|
||||||
|
@ -1108,7 +1108,7 @@ void lcQPropertiesTree::SetCamera(lcObject* Focus)
|
||||||
cameraFar->setData(0, PropertyValueRole, ZFar);
|
cameraFar->setData(0, PropertyValueRole, ZFar);
|
||||||
|
|
||||||
cameraName->setText(1, Name);
|
cameraName->setText(1, Name);
|
||||||
cameraName->setData(0, PropertyValueRole, QVariant::fromValue((void*)Name));
|
cameraName->setData(0, PropertyValueRole, Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcQPropertiesTree::SetLight(lcObject* Focus)
|
void lcQPropertiesTree::SetLight(lcObject* Focus)
|
||||||
|
|
Loading…
Reference in a new issue