#pragma once // FikatiaV2024 sistem yardimcilarinin C++23 portu: IFikoSinyaller (global sinyal), // IFikoSistem (ayarlar + dosya sistemi), IFikoNumokrator, IYardimciSiniflar, // vector3d. "I" oneki kaldirildi; koleksiyonlar 0-tabanli. // Ayar deposu Python sqlite3 ciktisiyla AYNI formattadir — post::fikodb ile // geriye uyumlu okunur/yazilir (tablolar: ayarlar, kategoriler). #include #include #include #include #include #include #include #include #include "com/model/belge_modeli.hpp" #include "post/fiko_post.hpp" namespace fikatia::sistem { // ---------------------------------------------------------------- sinyal ---- // IFikoSinyal portu. std::function kimlikle karsilastirilamadigindan sil() // fonksiyon yerine ekle()'nin dondurdugu baglanti kimligiyle calisir. class Sinyal { public: using Fonk = std::function; int ekle(Fonk fonk); void sil(int kimlik); void temizle() { fonksiyonlar_.clear(); } // Python birebir: bloke degilse sirayla cagirir, istisnalar yutulur. void calistir(const std::any& veri = {}) const; void operator()(const std::any& veri = {}) const { calistir(veri); } bool bloke() const { return bloke_; } void blokeAyarla(bool v) { bloke_ = v; } int sayisi() const { return static_cast(fonksiyonlar_.size()); } private: struct Kayit { int kimlik = 0; Fonk fonk; }; std::vector fonksiyonlar_; int sonKimlik_ = 0; bool bloke_ = false; }; // IFikoSinyaller portu: isimle erisilen sinyal yoksa yaratilir // (Python __getattribute__ davranisi). Tek-thread varsayimi. class Sinyaller { public: Sinyal& sinyal(std::string_view isim); bool varMi(std::string_view isim) const { return sinyaller_.find(isim) != sinyaller_.end(); } void yayinla(std::string_view isim, const std::any& veri = {}) { sinyal(isim).calistir(veri); } int sayisi() const { return static_cast(sinyaller_.size()); } private: std::map> sinyaller_; }; Sinyaller& globalSinyal(); // --------------------------------------------------------------- ayarlar ---- // IFikoAyar portu (db kolonlari: id, strID, ismi, degeri, degerTuru, aciklama, // simge, kategoriId, ekBilgiler). struct Ayar { std::int64_t id = 0; std::string strId; std::string ismi; std::string degeri; std::string degerTuru; std::string aciklama; std::string simge; std::int64_t kategoriId = 0; std::string ekBilgiler; bool degismis = false; int asInt() const; double asFloat() const; const std::string& asStr() const { return degeri; } bool asBool() const { return degeri == "True"; } std::string metin() const { return ismi + " -> " + degeri; } }; // IFikoAyarKategori portu (db kolonlari: id, ismi, aciklama, simge, // ustKategoriId, ekBilgiler). struct AyarKategori { std::int64_t id = 0; std::string ismi; std::string aciklama; std::string simge; std::int64_t ustKategoriId = 0; std::string ekBilgiler; }; // IFikoAyarKategoriler portu. class AyarKategoriler { public: int sayisi() const { return static_cast(tumu_.size()); } const AyarKategori* item(int indeks) const; const AyarKategori* item(std::string_view ismi) const; const std::vector& tumu() const { return tumu_; } std::string metin() const; // __str__: "['a', 'b']" private: friend class Ayarlar; std::vector tumu_; }; // IFikoAyarlar portu. Python yalniz okuyordu (kaydet pass'ti); burada degisen // kayitlar ayni SQLite semasina geri yazilir. class Ayarlar { public: Ayarlar() = default; static Ayarlar dosyadan(const std::string& yol); // hata: runtime_error int sayisi() const { return static_cast(tumu_.size()); } const Ayar* item(int indeks) const; Ayar* item(int indeks); const Ayar* item(std::string_view strId) const; Ayar* item(std::string_view strId); const std::vector& tumu() const { return tumu_; } const AyarKategoriler& kategoriler() const { return kategoriler_; } const AyarKategori* kategorisi(const Ayar& ayar) const; std::vector kategoriAyarlari(std::int64_t kategoriId) const; void degerAyarla(std::string_view strId, std::string deger); // yoksa sessiz void kaydet(); // degismis kayitlari dosyaya geri yazar private: std::string yol_; post::fikodb::VeriTabani vt_; std::vector tumu_; AyarKategoriler kategoriler_; }; // -------------------------------------------------------- dosya sistemi ---- // IFikoDosyaSistemi portu (durumsuz). struct DosyaSistemi { // glob esdegeri: klasordeki "*.exe" gibi desene uyan girdilerin adlari. static std::vector klasordekiDosyalar(const std::string& klasor, const std::string& uzantilar = "*.*"); // pencereGoster: SW_* sabiti (0 = gizli). Beklemez; basari doner. static bool programCalistir(const std::wstring& komutSatiri, int pencereGoster = 0); // Bitmesini bekler; cikis kodu doner (baslatilamadiysa bos). static std::optional programCalistirBekle(const std::wstring& komutSatiri, int pencereGoster = 0); }; // ---------------------------------------------------------- fiko sistem ---- // IFikoSistem portu: ayarlar + dosya sistemi cati nesnesi (sahip/anaProgram // COM zinciri duz veri portunda yok). class FikoSistem { public: explicit FikoSistem(const std::string& ayarDbYolu) : ayarlar_(Ayarlar::dosyadan(ayarDbYolu)) {} Ayarlar& ayarlar() { return ayarlar_; } const Ayarlar& ayarlar() const { return ayarlar_; } DosyaSistemi dosyaSistemi() const { return {}; } private: Ayarlar ayarlar_; }; // ------------------------------------------------------------ numokrator ---- // IFikoNumokratorItem portu (COM referanslari duz veriye indirildi). struct NumokratorOge { std::wstring ismi; std::wstring turu; // "IProduct" | "IPart" (Python birebir) std::wstring parcaNumarasi; int sayisi = 0; std::vector altOgeler; int altParcaSayisi() const { return static_cast(altOgeler.size()); } const NumokratorOge* altItem(int indeks) const; }; // IFikoNumokrator portu: urun agacini gezip parca numarasi -> adet sayimi. class Numokrator { public: explicit Numokrator(Product sahip) : sahip_(std::move(sahip)) {} int sayisi() const { return static_cast(ogeler_.size()); } NumokratorOge& ekle(NumokratorOge oge); NumokratorOge* item(int indeks); const NumokratorOge* item(int indeks) const; void sil(int indeks); const std::vector& ogeler() const { return ogeler_; } // Python hazirla (cift-recursion hatasi tek gecise indirildi). Gezerken // ogeler_ listesini de doldurur; toplam parca sayisi toplamParcaSayisi()'nda. std::map hazirla(); int toplamParcaSayisi() const { return toplam_; } private: int gez(const Product& urun, std::map& partlar); Product sahip_; std::vector ogeler_; int toplam_ = 0; }; // -------------------------------------------------------------- vector3d ---- inline constexpr double RAD2DEG = 180.0 / 3.14159265358979323846; inline constexpr double DEG2RAD = 3.14159265358979323846 / 180.0; inline constexpr double KUCUK = 1e-6; // Python birebir: abs alinmaz (is_near_zero). inline bool yakinSifirMi(double a) { return a < KUCUK; } struct Matris3; struct Vektor3 { double x = 0.0; double y = 0.0; double z = 0.0; Vektor3 operator+(const Vektor3& o) const { return {o.x + x, o.y + y, o.z + z}; } Vektor3 operator-(const Vektor3& o) const { return {x - o.x, y - o.y, z - o.z}; } Vektor3 operator-() const { return {-x, -y, -z}; } // Python birebir: fark bazli, abs'siz karsilastirma. bool operator==(const Vektor3& o) const { return yakinSifirMi(x - o.x) && yakinSifirMi(y - o.y) && yakinSifirMi(z - o.z); } void ayarla(double vx, double vy, double vz) { x = vx; y = vy; z = vz; } double uzunlukKare() const { return x * x + y * y + z * z; } double uzunluk() const; void olcekle(double oran) { x *= oran; y *= oran; z *= oran; } void birimYap() { olcekle(1.0 / uzunluk()); } Vektor3 olcekliVektor(double oran) const; Vektor3 birimVektor() const { return olcekliVektor(1.0 / uzunluk()); } Vektor3 paralelVektor(const Vektor3& eksen) const; Vektor3 dikVektor(const Vektor3& eksen) const { return *this - paralelVektor(eksen); } void donustur(const Matris3& m); std::string metin() const; // "(% .2f, % .2f, % .2f)" }; struct Matris3 { // e[i][j] = Python elem{i}{j}; birim matris olarak baslar. double e[4][4] = {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}; double eleman(int i, int j) const { return e[i][j]; } void elemanAyarla(int i, int j, double v) { e[i][j] = v; } bool operator==(const Matris3& o) const; Matris3 operator*(const Matris3& o) const; Vektor3 donusturVektor(const Vektor3& v) const; std::string metin() const; }; double aciNormallestir(double aci); double aciFarki(double aci1, double aci2); double icCarpim(const Vektor3& a, const Vektor3& b); Vektor3 caprazCarpim(const Vektor3& a, const Vektor3& b); double mesafeKare(const Vektor3& p1, const Vektor3& p2); double mesafe(const Vektor3& p1, const Vektor3& p2); double vektorAcisi(const Vektor3& a, const Vektor3& b); double konumAcisi(const Vektor3& p1, const Vektor3& p2, const Vektor3& p3); double vektorDihedral(const Vektor3& a, const Vektor3& eksen, const Vektor3& c); double konumDihedral(const Vektor3& p1, const Vektor3& p2, const Vektor3& p3, const Vektor3& p4); // Python kaynakta plane_normal tanimsizdi; ayni kutuphanenin (pdbremix) // orijinal tanimindan tamamlandi. Vektor3 duzlemNormali(const Vektor3& p1, const Vektor3& p2, const Vektor3& p3); Matris3 orijindeDonme(const Vektor3& eksen, double teta); Matris3 oteleme(const Vektor3& p); Matris3 donme(const Vektor3& eksen, double teta, const Vektor3& merkez); Vektor3 dondurulmusKonum(double teta, const Vektor3& baglanti, const Vektor3& merkez, const Vektor3& konum); Vektor3 izdusumKonum(double uzunluk, double aci, double dihedral, const Vektor3& p1, const Vektor3& p2, const Vektor3& p3); Matris3 superpozisyon3(const Vektor3& ref1, const Vektor3& ref2, const Vektor3& ref3, const Vektor3& mov1, const Vektor3& mov2, const Vektor3& mov3); Vektor3 rastgeleVektor(); Matris3 rastgeleOrijinDonme(); Matris3 rastgeleDonusum(); // ---------------------------------------------------- yardimci siniflar ---- using XYZ = Vektor3; // IYardimciSiniflar.XYZ ayni veri; ayri tip gereksiz struct IJK { double i = 0.0; double j = 0.0; double k = 0.0; }; struct XYZO { Vektor3 x, y, z, o; }; // SifirKonum portu: parca sifir noktasi cozumlemesi (kullaniciya gorunen // metinler Python birebir Turkce). struct SifirKonum { double xMin = 0.0, xMax = 0.0; double yMin = 0.0, yMax = 0.0; double zMin = 0.0, zMax = 0.0; bool miX0Merkez() const; bool miX0XEksiDuvar() const; bool miX0XArtiDuvar() const; bool miY0Merkez() const; bool miY0YEksiDuvar() const; bool miY0YArtiDuvar() const; bool miZ0Merkez() const; bool miZ0Taban() const; bool miZ0Ustu() const; double xOlcusu() const { return xMin + xMax; } double yOlcusu() const { return yMin + yMax; } double zOlcusu() const { return zMin + zMax; } std::string xSifir() const; std::string ySifir() const; std::string zSifir() const; std::string toStr() const; // "X0=... Y0=... Z0=..." }; } // namespace fikatia::sistem